Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

I am having trouble adding a sheild onto my enemy

Discussion in 'Scripting' started by ardizzle, Aug 18, 2014.

  1. ardizzle

    ardizzle

    Joined:
    Mar 28, 2013
    Posts:
    86
    I have an enemy with a shield prefab as a child. When my ally hits the enemy the enemy takes damage. But when my ally hits the shield the enemy takes damage. The ally knows he hit an enemy by checking the tag. So I tried having him check the tag of the shield but it still damages the enemy. My guess is because the child is following the tag of the parent. What is the best way to get around this?
     
  2. Aidenjl

    Aidenjl

    Joined:
    Jan 5, 2014
    Posts:
    81
    Have you tried using this?
    if(hit.collider.gameObject.CompareTag("shield")){

    }
     
  3. ardizzle

    ardizzle

    Joined:
    Mar 28, 2013
    Posts:
    86
    I did not but I will keep it mind. I ended up making a work around that might help more in the future. I made a equip script where I drop the object into the inspector and then follows the enemy from there. Thank you for the info