Hi Guys. I got this problem where mobs enter my trigger for AOE and then gets damaged and slowed down. When the mob exist the damage stop and speed reduction stops. My problem is when the mobs are in the area and the area timer runs out. the Area damage spell gets destroyed but only one of the enemies speed gets set back to normal. How can I store all the enemies entering that area to assign there speed back to them. My Script is as followed.
var enter : boolean = false;
private var damage :int;
var minDamage: int = 1;
var maxDamage: int = 4;
var enemy : Transform;
var timer : float;
var i;
var countdown : float;
var speed : float;
function Start(){
countdown = timer;
}
function Update () {
countdown-=Time.deltaTime;
if(enter == true){
}
if(countdown <=0)
{
enemy.SendMessage("ApplySlow", false,SendMessageOptions.DontRequireReceiver);
enemy.GetComponent(NavMeshAgent).speed=speed;
Destroy(gameObject);
}
}
function OnTriggerEnter (col : Collider){
if (col.tag == "Enemy") {
enemy=col.transform;
speed = enemy.GetComponent(NavMeshAgent).speed;
col.GetComponent(NavMeshAgent).speed=speed/2;
col.SendMessage("ApplySlow", true,SendMessageOptions.DontRequireReceiver);
enter = true;
for ( i= 0; i < 1000000; i++){
damage = Random.Range(minDamage,maxDamage);
col.SendMessage("ApplyDamage", damage,SendMessageOptions.DontRequireReceiver);
Debug.Log(gameObject.transform.name + " caused "+ damage + " Damage to Player");
yield WaitForSeconds(0.5);
//this will deduct health per second as long as the enemy is in the trigger
}
}
}
function OnTriggerExit (col : Collider){
if (col.tag == "Enemy") {
col.SendMessage("ApplySlow", false,SendMessageOptions.DontRequireReceiver);
col.GetComponent(NavMeshAgent).speed=speed;
(enter) = false;
}
}
Sorry if this isn’t of much help I don’t really use JS so I can’t provide any code but for storing multiple transforms I would suggest making an array for Transform and storing any mobs that collide with the area in there.
Because your not using an array it’s only taking the effect off the most recent mob that has entered the area.
Hopefully this link might help
http://docs.unity3d.com/ScriptReference/Array.html
Ok So I trashed the Objects idea and gone with the List. This works except one thing that is not going as it should. When the First enemy enters the area the Damage get applies to the list. When the second enemy get in. The damage get applied twice. Now when the first enemy leaves the first enemy still get damaged. Think something in my TriggerEnter
var enter : boolean = false;
private var damage :int;
var minDamage: int = 1;
var maxDamage: int = 4;
var enemy : Transform;
var timer : float;
var countdown : float;
var speed : float;
var myArrayList = new ArrayList();
function Start()
{
countdown = timer;
}
function Update ()
{
countdown-=Time.deltaTime;
var howBig = myArrayList.Count;
//Prints How many items in the List
//print(howBig);
if (myArrayList.Count >0)
{
if(countdown <=0)
{
for(var i:int=0; i<myArrayList.Count; i++)
{
Debug.Log(myArrayList*.name+ i );*
_ myArrayList*.SendMessage(“ApplySlow”, false,SendMessageOptions.DontRequireReceiver);_
_ myArrayList.GetComponent(NavMeshAgent).speed=speed;
Destroy(gameObject);
}
}
}*_
* } *
function OnTriggerEnter (col : Collider)
* {*
* if (col.tag == “Enemy”) *
* {*
* myArrayList.Add(col);*
* speed = col.GetComponent(NavMeshAgent).speed;*
* col.GetComponent(NavMeshAgent).speed=speed/2;*
* col.SendMessage(“ApplySlow”, true,SendMessageOptions.DontRequireReceiver);*
* enter = true;*
* for ( var a= 0; a < 1000000; a++)*
* {*
* for(var b:int=0; b<myArrayList.Count; b++) *
* {*
* damage = Random.Range(minDamage,maxDamage); *
_ myArrayList**.SendMessage(“ApplyDamage”, damage,SendMessageOptions.DontRequireReceiver);_
__ Debug.Log(gameObject.transform.name + " caused “+ damage + " Damage to Enemies” + myArrayList.name);
yield WaitForSeconds(0.5);
}
}
}**__
** }**
function OnTriggerExit (col : Collider)
** {**
** for(var i:int=0; i<myArrayList.Count; i++)**
** {**
__ if(col == myArrayList*)
{ __
_ myArrayList.SendMessage(“ApplySlow”, false,SendMessageOptions.DontRequireReceiver);
myArrayList.GetComponent(NavMeshAgent).speed=speed;
Debug.Log(myArrayList.name + i+ “Left the Area” );
}
enter = false;
}
}*_