- Home /
Need help fixing my script
Im trying to disable a script and play animation when coliding with an object with a tag.
#pragma strict
public var gameObject : GameObject;
function Update () {
}
function OnTriggerEnter (col : Collider) {
if(col.gameObject.tag == "Weapon") {
GameObject.GetComponent(Chase).enabled = false;
GetComponent.<Animation>().Play();
}
}
Answer by UnityCoach · Aug 01, 2017 at 10:30 PM
I guess you want to replace
GameObject.GetComponent(Chase).enabled = false;
with
gameObject.GetComponent(Chase).enabled = false;
Assets/die.js(10,5): BCE0004: Ambiguous reference 'gameObject': die.gameObject, UnityEngine.Component.gameObject.
ah yes, you have to rename gameObject to something else (i.e.: _otherGameObject), otherwise it gets mixed up with the gameObject accessor.
Anyway, my UnityScript isn't what it was.. Here in C#, just in case
public class Die : $$anonymous$$onoBehaviour
{
public GameObject _gameObject;
void Update ()
{
}
void OnTriggerEnter (Collider col)
{
if (col.gameObject.tag == "Weapon")
{
_gameObject.GetComponent<Chase>().enabled = false;
GetComponent<Animation>().Play();
}
}
}
Your answer
Follow this Question
Related Questions
How do I make do I make a variable go back to its original value for a spell system 1 Answer
3rd Person Camera to Rotate With the Player 0 Answers
How do I make my projectile deal damage to a target it hit. 1 Answer
Trying to find the highest number than add it to itself. 2 Answers
Point Counter Works Only Once! 1 Answer