- Home /
This question was
closed Jul 27, 2015 at 04:50 PM by
meat5000 for the following reason:
The question is answered, right answer was accepted
Question by
Nick_Rizzo · Jul 27, 2015 at 09:58 AM ·
unity 5javascriptraycasttagraycasthit
Switch GameObjects Tags with javascript
So I'm trying to close and open multiple doors with a script and here it is basically I'm just trying to switch tags but the tags won't switch. Please Help Thanks!
`function Update ()
{
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5,Screen.height*0.5, 0));
if (hit.collider.gameObject.tag == "Door")
{
if(Input.GetKeyDown("e"))
{
hit.collider.gameObject.GetComponent.<Animation>().Play("DoorOpen");
hit.collider.gameObject.tag = "Close";
}
}
if (hit.collider.gameObject.tag == "Close")
{
if(Input.GetKeyDown("e"))
{
hit.collider.gameObject.GetComponent.<Animation>().Play("DoorOpen");
hit.collider.gameObject.tag = "Door";
}
}
}
`
Comment
Best Answer
Answer by Nick_Rizzo · Jul 27, 2015 at 04:46 PM
Ok so I was able to fix it by making the close statement else if instead of if and I made all the animations legacy.
Follow this Question
Related Questions
Raycast script help? 1 Answer
Raycast tag/ Null reference exception? 1 Answer
Bug/Error in script CollectPapers 0 Answers
How to assign a Variable with a Raycast 1 Answer
Multiple raycasts from game object 0 Answers