- Home /
How do I code a shield for a spaceshooter?
I am currently working on a spaceshooter where I began following the Unity tutorial and then upgraded it afterwards. Currently I am trying to make a shield for the player where it will block a shot or a collision with the enemy and the disappear. But I can't make it work, I have the shield object as a child to the player and a script in it that uses tags to deactivate it, but it doesn't work.
Here is the code: (I have code in another script where you press "1" to set shieldActive to true)
private void Update()
{
if (shieldActive == true)
{
gameObject.SetActive(true);
}
}
void OnTriggerEnter(Collider other)
{
if (shieldActive == true)
{
if (other.CompareTag("Shield"))
{
Destroy(other.gameObject);
gameObject.SetActive(false);
shieldActive = false;
Debug.Log(other.gameObject);
}
}
}
Your answer
Follow this Question
Related Questions
Best way to only run only one part of a script at a time? 0 Answers
How can I make the Unity Standard Asset plane move in a scripted manner? 1 Answer
SetActive() not working 0 Answers
reactivate object after seconds not work? 1 Answer
How do I change a gameobject to be active through a script? 1 Answer