Hi i have problem with monsters from my spawner. I`m trying to use freeze on my monsters. To do this if i hit some monster i change his speed to 0. After this i calculate few seconds in another method and change speed of my monster again on start value. First part works great, but after few seconds my script is changing speed of another random monster from spawner, not exacly freeze one. I think problem is related with Update. All this code is in HealthScript.cs in MonsterObjectPrefab. In the same object i have MovementScript.cs and i get it on start function. Like is write if i change speed only when i hit monster it works good, but if change is in update evene once it working on random object with the same name
Is there some option to chenge speed only and exacly in this one monster object in MonsterScript.cs?
MovementScript move;
void Start() {
move = GetComponent<MovementScript>();
}
void OnTriggerEnter2D (Collider2D collider) {
ShotScript shot = collider.gameObject.GetComponent<ShotScript> ();
if (shot != null)
{
if (shot.isHit != isEnemy)
{
PlayerData.hittedEnemys++;
EffectOn(PlayerActiveSkills.actualActiveSkill);
HP -= shot.damage;
enemyHpBar.value = HP;
if(imOnIce)
move.speed = new Vector2(0,0);
}
}
}
void EffectOn( SkillType effectType ) {
if(effectType == SkillType.IceArrow)
imOnIce = true;
}
void OnIceEffect() {
iceArrowTimeDuration[0] += Time.deltaTime;
if(iceArrowTimeDuration[0] >= 1) {
iceArrowTimeDuration[1]++;
iceArrowTimeDuration[0] = 0;
if(iceArrowTimeDuration[1] >= 10){
iceArrowTimeDuration[1] = 1;
imOnIce = false;
move.speed = new Vector2(150,10);
Debug.Log("FReez End" + move.speed);
}
}
void Update () {
if(imOnIce)
OnIceEffect();
}