- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
SixPence · Apr 11, 2013 at 05:08 AM ·
prefabsinstantiation
Attacking a Prefab
Instantiation of a player prefab is not recognizing an Instantiated enemy prefab.
void Update ()
{
if(Vector3.Distance(transform.position, Enemy_Troop.transform.position) <100 &&
Vector3.Distance(transform.position, Enemy_Troop.transform.position) > 1)
{
transform.LookAt(Enemy_Troop.transform);
transform.Translate(Vector3.forward * speed * Time.smoothDeltaTime);
Debug.Log ("hit");
FightDistance = true;
Fighting ();
}
if(health == 0)
{
Destroy (gameObject);
}
what am i doing wrong ??
Comment
Answer by Vonni · Apr 11, 2013 at 03:22 PM
//Tidy up code: Easier to read and easier to adjust
float distance = Vector3.Distance(transform.position, Enemy_Troop.transform.position);
if(distance < 100 && distance > 1)
And what is = Enemy_Troop Is this a variable somewhere in this script? Like: Transform Enemy_Troop; If so, it's good practice to write variables like enemyTroop or _EnemyTroop (Easier to read when things get complicated.
And if both this script and enemy script have been instantiated in game, you wont have any connection between the two as far as I can see in this code.
Your answer
