Mail.ruПочтаМой МирОдноклассникиВКонтактеИгрыЗнакомстваНовостиКалендарьОблакоЗаметкиВсе проекты

ОШИБКА С ПАРТИКЛАМИ В ЮНИТИ 2Д

hgh gffd Ученик (89), на голосовании 6 месяцев назад
Вообщем, создал я партиклы при смерти врага, написал в коде врага чтобы при смерти появились партиклы, но дело в том что при запуске игры они сразу появляются
вот код врага:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy : MonoBehaviour
{
private float timeBtwAttack;
public float startTimeBtwAttack;

public int health;
public float speed;
public int damage;
private float stopTime;
public float startStopTime;
public float normalSpeed;
private Player player;
private Animator anim;
public GameObject effect;

private void Start()
{
anim = GetComponent<Animator>();
player = FindObjectOfType<Player>();
}

void Update()
{

if(stopTime <= 0)
{
speed = normalSpeed;
}
else
{
speed = 0;
stopTime -= Time.deltaTime;
} // эта нижняя строчка отвечает за появления партикла при смерти врага
Instantiate(effect, transform.position, Quaternion.identity);
if (health <= 0)
{
Destroy(gameObject);
}
if(player.transform.position.x > transform.position.x)
{
transform.eulerAngles = new Vector3(0,180,0);
}
else
{
transform.eulerAngles = new Vector3(0,0,0);
}
transform.position = Vector2.MoveTowards(transform.position, player.transform.position, speed * Time.deltaTime);
}

public void TakeDamage(int damage)
{ stopTime = startStopTime;
health -= damage;
}
private void OnTriggerStay2D(Collider2D other)
{
if(other.CompareTag("Player"))
{
if(timeBtwAttack <= 0)
{
anim.SetTrigger("EnemyAttack");
}
else
{
timeBtwAttack -= Time.deltaTime;
}
}
}
public void OnEnemyAttack()
{
player.ChangeHealth(-damage);
player.health -= damage;
timeBtwAttack = startTimeBtwAttack;
}
}


Вот фото что происходит при запуске игры:
Голосование за лучший ответ
Похожие вопросы