,Changing the variable on only one object
So I have a script that makes an enemy shoots invisible dots that are supposed to make the enemy go agressive if they hit something. The problem is, I only want the enemy that shoot that dot to go agressive. Heres the code on the enemy:
private void FixedUpdate()
{
interval += 1;
if (interval % 50 == 0)
{
isAgro = false;
searchTarget();
if (isAgro)
{
makeAgro();
}
}
else if (interval == 51) interval = 0;
}
void searchTarget()
{
Vector2 getDir = target.transform.position - enemy.position;
float distDir = getDir.magnitude;
getDir = getDir / distDir;
getDir.Normalize();
GameObject liveDot = Instantiate(dotPf) as GameObject;
liveDot.transform.position = new Vector3(enemy.position.x, enemy.position.y, 0);
liveDot.GetComponent<Rigidbody2D>().velocity = getDir * dotSpeed;
}
void makeAgro()
{
}
and here's the script attached to the dot prefab
void FixedUpdate()
{
TTL += 0.2f;
if (TTL > maxTTL) Destroy(gameObject);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Wall")
{
Destroy(gameObject);
}
else if (other.tag == "Player")
{
enemyController.isAgro = true;
Destroy(gameObject);
}
}
Any hints or suggestions how can i solve this?
Comment
But how are you declaring the variables? If they are not static, each object should have its own code independent from other objects.
What is happening in your game and what you want to get?
Your answer
Follow this Question
Related Questions
[Help] Getting variable based on string value. 2 Answers
can't access a public static int from another class. Value is always zero 2 Answers
Static bool 1 Answer
Change of static variable 1 Answer