Tower defense: Tower play animation when enemy appear
Hi .. I would like to ask about play animation on tower I have my own 3d model swordsman and it has attack animation on it and see i have this tower defense game .. My tower prefab is a swordsman, now when i put my tower on a platform how to activate its animation when the swordsman see the enemy like swing his sword
Do you have any seeing logic working already? If not, what do you consider seeing? 180° infront? 360°? Be more precise.
Is the animator of the swordsman already setup? does it have transitions based on triggers or bools that make him swing the sword? (can be tested in play mode by just toggling the values in the animator window).
Answer by $$anonymous$$ · Mar 04, 2017 at 11:42 AM
What i suggest is you make a cube (object) in the area Infront of the tower/Swordsman, with the mesh renderer off, then on cube collider select is trigger...
Then all you have to do is attach this script to the swordsman..
// C# code
void OnTriggerEnter(Collider Obj)
{
if(Obj.tag == "Enemy")
{
gameobject.Getcomponent<Animation>().Play("SwordSwing");
}
}
// Give the enemy obj the enemy tag
And if you have a giveDamage function you could call that as well.. inside the area.
Its seem there is a problem to your script sir.. i just copy your script
Assets/SCRIPTS/Attack.js(3,7): UCE0001: ';' expected. Insert a semicolon at the end. Assets/SCRIPTS/Attack.js(3,32): BCE0044: expecting ), found 'Obj'. Assets/SCRIPTS/Attack.js(3,35): BCE0043: Unexpected token: ). Assets/SCRIPTS/Attack.js(7,46): BCE0043: Unexpected token: ). Assets/SCRIPTS/Attack.js(7,47): BCE0044: expecting ), found '.'. Assets/SCRIPTS/Attack.js(7,48): UCE0001: ';' expected. Insert a semicolon at the end.