I am trying to get my player to die when it hits thee ground. This is my code Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class FallingPlayer : MonoBehaviour { GameObject Player; float CurrentFallTime; public float MaxFallTime = 3; bool PlayerIsFalling; bool isGrounded; void Update() { if (Player.isGrounded == false) { PlayerIsFalling = true; } else PlayerIsFalling = false; if (PlayerIsFalling) { CurrentFallTime += Time.deltaTime; } if (Player.isGrounded && CurrentFallTime < MaxFallTime) { CurrentFallTime = 0; } if (CurrentFallTime >= MaxFallTime && Player.isGrounded) { GameManager.Instance.FallOxygen(); } } } and these are the errors i am getting: Assets\FallingPlayer.cs(15,20): error CS1061: 'GameObject' does not contain a definition for 'isGrounded' and no accessible extension method 'isGrounded' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?) Assets\FallingPlayer.cs(25,20): error CS1061: 'GameObject' does not contain a definition for 'isGrounded' and no accessible extension method 'isGrounded' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?) Assets\FallingPlayer.cs(30,54): error CS1061: 'GameObject' does not contain a definition for 'isGrounded' and no accessible extension method 'isGrounded' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?)
You are not assigning nothing to the variable type GameObject "Player", this is why you get the error. If you want to assign the player object you have to declare "public GameObject Player" and then in the inspector you can drag your player object. Anyway i think you would get the error in that case too because a game object type doesn't have a "isGrounded" variable so you can't access to it
What components have you attached to the player object? What components have you attached to the player object?
If you want to access to the variable isGrounded, assuming it's inside PlayerControl script, you can do something like this: bool isGrounded = GetComponent<PlayerControl>().isGrounded
now i get this : Assets\fallplayer.cs(10,23): error CS0236: A field initializer cannot reference the non-static field, method, or property 'Component.GetComponent<PlayerControl>()'
I think you are missing how Unity works. Do you have a script "PlayerControl" attached to the player object and is there a public variable called isGrounded? Is there attached the script "FallingPlayer" to the player object?
You have to do the GetComponent<PlayerControl>() bit inside a function, it can't be up where the bool is declared on the class. So either move the whole line inside Update(), or only declare your bool up at the top, and set its value with GetComponent inside Update()