- Home /
Another function for activating a different script
So I have this problem, basically my aihealth script relies on triggers and i want to do the same with the player detection but then they would share different triggers for different purposes..Any fix?
what do you mean by different triggers? you can compare the tag of the collider you are colliding with and use if statements for doing one logic or another, if this is your question.
Ok Thank you well here is the code:
{ public int Pain = 2; public float hitLast = 0; public float hitDelay = 1;
void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Player")
{
if (Time.time - hitLast < hitDelay)
return;
Vector3 damageDirection = other.transform.position - transform.position;
damageDirection = damageDirection.normalized;
FindObjectOfType<PlayerHealth>().DamagePlayer(Pain, damageDirection);
hitLast = Time.time;
}
}
}
And the problem is I wanted to make a trigger function, where, if the player ever enters it the target would be given and therefore chase the player BUT the problem is i have another script attached to the ai which receives damage from the player using the trigger function, so it would be a mess right? the ai would receive damage from the player without even getting close to the ai
here is the damage code:
{ public int Pain = 2; public float hitLast = 0; public float hitDelay = 1;
void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Player")
{
if (Time.time - hitLast < hitDelay)
return;
Vector3 damageDirection = other.transform.position - transform.position;
damageDirection = damageDirection.normalized;
FindObjectOfType<PlayerHealth>().DamagePlayer(Pain, damageDirection);
hitLast = Time.time;
}
}
}
hello, you can create an empty gameobject child of the player withanother tag something like PlayerRange and inside the ontriggerstay compare if the trigger you are collising is the player or the playerrange. you can make the triggerrange collider bigger for that porpuse.
Got any examples of your issue, images, code. more details
Good day.
You are not giving information. We dont understand what you say. Please explain, give code, give examples...
Ok Thank you well here is the code:
{
public int Pain = 2;
public float hitLast = 0;
public float hitDelay = 1;
void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Player")
{
if (Time.time - hitLast < hitDelay)
return;
Vector3 damageDirection = other.transform.position - transform.position;
damageDirection = damageDirection.normalized;
FindObjectOfType<PlayerHealth>().DamagePlayer(Pain, damageDirection);
hitLast = Time.time;
}
}
}
And the problem is I wanted to make a trigger function, where, if the player ever enters it the target would be given and therefore chase the player BUT the problem is i have another script attached to the ai which receives damage from the player using the trigger function, so it would be a mess right? the ai would receive damage from the player without even getting close to the ai
here is the damage code:
{
public int Pain = 2;
public float hitLast = 0;
public float hitDelay = 1;
void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Player")
{
if (Time.time - hitLast < hitDelay)
return;
Vector3 damageDirection = other.transform.position - transform.position;
damageDirection = damageDirection.normalized;
FindObjectOfType<PlayerHealth>().DamagePlayer(Pain, damageDirection);
hitLast = Time.time;
}
}
}
Ok Thank you well here is the code:
{ public int Pain = 2; public float hitLast = 0; public float hitDelay = 1;
void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Player")
{
if (Time.time - hitLast < hitDelay)
return;
Vector3 damageDirection = other.transform.position - transform.position;
damageDirection = damageDirection.normalized;
FindObjectOfType<PlayerHealth>().DamagePlayer(Pain, damageDirection);
hitLast = Time.time;
}
}
}
And the problem is I wanted to make a trigger function, where, if the player ever enters it the target would be given and therefore chase the player BUT the problem is i have another script attached to the ai which receives damage from the player using the trigger function, so it would be a mess right? the ai would receive damage from the player without even getting close to the ai
here is the damage code:
{ public int Pain = 2; public float hitLast = 0; public float hitDelay = 1;
void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Player")
{
if (Time.time - hitLast < hitDelay)
return;
Vector3 damageDirection = other.transform.position - transform.position;
damageDirection = damageDirection.normalized;
FindObjectOfType<PlayerHealth>().DamagePlayer(Pain, damageDirection);
hitLast = Time.time;
}
}
}
Your answer
Follow this Question
Related Questions
Script is only working on original object 2 Answers
Ontrigger not working with npc 0 Answers
Animator trigger keeps retriggering. 0 Answers
Enemy evade sight of player 1 Answer
Enemy doesn't avoid static objects 2 Answers