Get coordinates of player

My CSharp script , the player’s y is > 0 but the script still runs!

using UnityEngine;
using System.Collections;

public class PlayerCollisioner : MonoBehaviour {
	void Start () {

	void Update () {
		if(gameObject.transform.position.y < 10){
			Debug.Log("under world");

I tested your script and it works fine. There is no problem with the script.

Based on logic from your code:

  • The issue might be that the ‘y’ position of your game object is greater than or equal to 10 which is why that game object is not getting destroyed and the Update() in it will be called on each frame.
  • Or this script might be attached to multiple game objects and even though the one game object is getting deleted other are still present and they are producing the output as per the scenario #1.

Based on ‘My CSharp script, the player’s y is > 0 but the script still runs!’

If you want game object to be deleted after its ‘y’ is greater than 0 then you should check for:

if(gameObject.transform.position.y > 0)