Having an issue John Lemon in the 7th step. Enemies Part 1; Static Observer. step 11, Complete your Gargoyle Prefab. 1. In the last if statement of the Update method, add the following code: Code (CSharp): gameEnding.CaughtPlayer (); You can add this here because the CaughtPlayer method is public. If it was private, your code editor would report an error with this line. So I did that but i get an error for it. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class GameEnding : MonoBehaviour { public float fadeDuration = 1f; public float displayImageDuraction = 1f; public GameObject player; public CanvasGroup exitBackgroundImageCanvasGroup; public CanvasGroup caughtBackgroundImageCanvasGroup; bool m_IsPlayerAtExit; bool m_IsPlayerCaught; float m_Timer; private void OnTriggerEnter(Collider other) { if (other.gameObject == player) { m_IsPlayerAtExit = true; } } public void CaughtPlayer() { m_IsPlayerCaught = true; } void Update() { if (m_IsPlayerAtExit) { Endlevel(exitBackgroundImageCanvasGroup, false); } else if (m_IsPlayerCaught) { Endlevel(caughtBackgroundImageCanvasGroup, true); gameEnding.CaughtPlayer(); } } void Endlevel(CanvasGroup imageCanvasGroup, bool doRestart) { m_Timer += Time.deltaTime; imageCanvasGroup.alpha = m_Timer / fadeDuration; if (m_Timer > fadeDuration + displayImageDuraction) { if (doRestart) { SceneManager.LoadScene(0); } else { Application.Quit(); } } } } Then I though the upercase and lowercase may be wrong in the documents so i used it With GameEnding rather then gameEnding (I still got and error so not sure what to do now? Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class GameEnding : MonoBehaviour { public float fadeDuration = 1f; public float displayImageDuraction = 1f; public GameObject player; public CanvasGroup exitBackgroundImageCanvasGroup; public CanvasGroup caughtBackgroundImageCanvasGroup; bool m_IsPlayerAtExit; bool m_IsPlayerCaught; float m_Timer; private void OnTriggerEnter(Collider other) { if (other.gameObject == player) { m_IsPlayerAtExit = true; } } public void CaughtPlayer() { m_IsPlayerCaught = true; } void Update() { if (m_IsPlayerAtExit) { Endlevel(exitBackgroundImageCanvasGroup, false); } else if (m_IsPlayerCaught) { Endlevel(caughtBackgroundImageCanvasGroup, true); GameEnding.CaughtPlayer(); } } void Endlevel(CanvasGroup imageCanvasGroup, bool doRestart) { m_Timer += Time.deltaTime; imageCanvasGroup.alpha = m_Timer / fadeDuration; if (m_Timer > fadeDuration + displayImageDuraction) { if (doRestart) { SceneManager.LoadScene(0); } else { Application.Quit(); } } } }
Error in as that it dose not work. The Photos with the red underline is where it shows that something is not right Visual Studios does that. not sure if this helps but if I have Code (CSharp): GameEnding.CaughtPlayer(); it says = an object reference is required for the non-static field, method, or property "GameEnding.CaughtPlayer();" and if I have Code (CSharp): gameEnding.CaughtPlayer(); it says = The name 'gameEnding' Does not exist in the current contect
Not in Visual Studio. In the Unity console, it should report an error message. You can't fix the error unless you know what it is.
Assets\Scripts\GameEnding.cs(41,13): error CS0120: An object reference is required for the non-static field, method, or property 'GameEnding.CaughtPlayer()'
Just call CaughtPlayer(); Replace your GameEnding.CaughtPlayer(); and/or gameEnding.CaughtPlayer(); by Code (CSharp): CaughtPlayer();
Be careful which file you're updating.. The tutorial switches between the Observer.cs file and the GameEnding.cs file pretty quick you want to add that bit to the Observer.cs file
You have remove the GameEnding.CaughtPlayer(); else if (m_IsPlayerCaught) { Endlevel(caughtBackgroundImageCanvasGroup, true); GameEnding.CaughtPlayer(); } } and place it under observer.cs under the last if statement if(raycastHit.collider.transform == player) { gameEnding.CaughtPlayer(); }
I'm having the same issue.... and I went back and cut / pasted his code and still not running Initially - in Unity (and In Visual Studio) Assets\Scripts\Observer.cs(49,21): error CS0103: The name 'gameEnding' does not exist in the current context .... changed to GameEnding Assets\Scripts\Observer.cs(50,21): error CS0120: An object reference is required for the non-static field, method, or property 'GameEnding.CaughtPlayer()' and per fixes (sorry abi) Assets\Scripts\Observer.cs(50,18): error CS0103: The name 'CaughtPlayer' does not exist in the current context (sorry Sairam) You have remove the GameEnding.CaughtPlayer(); - did that
gameEnding.CaughtPlayer(); Here the the object "gameEnding" is undefined so you cannot call a function of an undefined object. Declare a game object of class "GameEnding". Put "public GameEnding gameEnding; in the beginning of your class. it will solve the issue.
I've completed this tutorial successfully. Now I want to build the game for Android platform. Can anyone help me to write the scripts for the movement on touchscreen associated to this game.Thanks in Advance
i have this error NullReferenceException: Object reference not set to an instance of an object PlayerMovement.OnAnimatorMove () (at Assets/Scripts/PlayerMovement.cs:34) step tutorial,the code is exactly in that tutorial Code (CSharp): void OnAnimatorMove() { m_Rigidbody.MovePosition(m_Rigidbody.position + m_Movement * m_Animator.deltaPosition.magnitude); m_Rigidbody.MoveRotation(m_Rotation); } regards
"NullReferenceException: Object reference not set to an instance of an object" means that one of your objects has the value null, which means that it is unassigned. The error occurs at line 34, which means that that is where the object is used. From the code snippet you posted, it could be m_Rigidbody, m_Movement, m_Animator or m_Rotation. Rigidbody and animator seem the most likely culprits to me. You have to go back to the tutorial and see how these values are assigned. This can be done in the inspector, or in code using a statement that looks something like "m_Rigidbody = GetComponent<Rigidbody>();"