- Home /
Can't reactivate object
Ok, so I made a Torch in my game that I want you to be able to put away and bring back at will. It has to be deactivated so its light quits shining too. It goes away fine, but when I press the button to bring it back the animation will play but it doesn't reactivate. The object does have children. I think I might have something wrong with my script because I'm brand new to scripting. This is my scrip so far. I have the script on a parent object "melee" so the script wouldn't get deactivated along with the rest of the object. The two functions at the end are set as events in the animations. If you guys can help me out that'd be great.
#pragma strict
var Torch : GameObject;
function Start ()
{
Torch = GameObject.Find("player/Main Camera/melee/Torch");
}
function Update ()
{
if(Input.GetKeyDown(KeyCode.T))
{
Torch.animation.CrossFade("TorchAway");
}
if(Input.GetKeyDown(KeyCode.Y))
{
Torch.animation.CrossFade("TorchReturn");
}
}
function TorchAway ()
{
Torch.SetActive(false);
}
function TorchReturn ()
{
Torch.SetActive(true);
}
does the object stay in the inspector when it is false ?
Answer by TonyLi · Jul 11, 2013 at 01:14 PM
Since Torch is inactive, this line won't run:
Torch.animation.CrossFade("TorchReturn");
Instead, try this:
if(Input.GetKeyDown(KeyCode.Y))
{
Torch.SetActive(true);
Torch.animation.CrossFade("TorchReturn");
}
If the TorchAway animation has played, I'm guessing it has faded out the torch somehow. So when you activate it on KeyCode.Y, it should basically be invisible until TorchReturn finishes playing.
If that doesn't work, you could get more complicated and disable the torch's MeshRenderer until TorchReturn() gets called.
Your answer
![](https://koobas.hobune.stream/wayback/20220613105855im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rigidbody help 0 Answers
Error BCE0019 1 Answer
Player using turret problem 1 Answer
Invalid SceneHandle 0 Answers
How to add OnClick listener in script to see it in inspector? 1 Answer