- Home /
Trying to Activate game object on condition
I am trying to activate my gameobject when my "player" y position is set to my PlayerHeight float. This code is not pulling an error but it simply does nothing when attached to the target object that I am trying to activate. this question is probobly really stupid but I am new enough to C# coding. Spare with me please. :) Here is my code:
using UnityEngine;
using System.Collections;
public class WaterFlip : MonoBehaviour {
public float PlayerHeight;
// Use this for initialization
void Start () {
}
void Update () {
if (GameObject.Find("FPSController").transform.position.y < PlayerHeight) {
gameObject.SetActive (true);
}
}
}
Thanks,
CaptainChaos
Answer by Ricewind1 · Jun 11, 2015 at 04:54 AM
"Making a GameObject inactive will disable every component, turning off any attached renderers, colliders, rigidbodies, scripts, etc... Any scripts that you have attached to the GameObject will no longer have Update() called, for example."
You'd have to set it active from an outside script or mimic the 'isactive' depending on what you want to achieve with it.
Your answer
Follow this Question
Related Questions
Cannot deactivate / activate gameobject, even in editor! 6 Answers
Checking if a position is occupied in 2D? 1 Answer
Gameobject Inspector display is ... different 3 Answers
What is the best way to manage gameobjects in a scene to conserve memory? 0 Answers
Unity - How to activate a canvas or gameobject when a scene restarts? 2 Answers