Hi
how to to compare the y of player and ocean? Something with transform?
Thanks
if(player.transform.position.y < waterLevel.transform.position.y)
{
// underwater
}
player = GameObject.FindGameObjectWithTag(Player).transform;
returns player is not available in current context.
My script is attached to Player (with a tag player).
Many thanks
You mean to use FindWithTag right? GameObject.FindGameObjectsWithTag returns you an array of game objects. Also, FindWithTag takes in a string (case-sensitive).
Did you check if you typed in the tag correctly?
Thanks, I even wonder if i need to do alike as it’s attached to Player. Well I get:
private Transform Player; // Reference to the player’s transform.
player = GameObject.FindWithTag(Player).transform;
returns:
Assets/myUnderwater.cs(45,37): error CS1502: The best overloaded method match for UnityEngine.GameObject.FindWithTag(string)' has some invalid arguments Assets/myUnderwater.cs(45,37): error CS1503: Argument
#1’ cannot convert UnityEngine.Transform' expression to type
string’
if I try:
private GameObject player;
player = GameObject.FindWithTag(Player).transform;
I get:
Assets/myUnderwater.cs(46,49): error CS0103: The name `Player’ does not exist in the current context