我的问题是,所有三个enemys在同一时间拍摄。我先要然后第二个然后第三个开始拍摄。
这里是我的代码:
public float speed = 7f;
public float attackDelay = 3f;
public Projectile projectile;
private Animator animator;
public AudioClip attackSound;
void Start() {
animator = GetComponent<Animator>();
if(attackDelay > 0){
StartCoroutine(onAttack());
}
}
void Update() {
animator.SetInteger("AnimState", 0);
}
IEnumerator onAttack(){
yield return new WaitForSeconds(attackDelay);
fire();
StartCoroutine(onAttack());
}
void fire(){
animator.SetInteger("AnimState", 1);
if(attackSound){
AudioSource.PlayClipAtPoint(attackSound, transform.position);
}
}
void onShoot(){
if (projectile){
Projectile clone = Instantiate(projectile, transform.position, Quaternion.identity)as Projectile;
if(transform.localEulerAngles.z == 0){
clone.rigidbody2D.velocity = new Vector2(0, transform.localScale.y) * speed * -1;
}
else if(Mathf.RoundToInt(transform.localEulerAngles.z) == 90){
clone.rigidbody2D.velocity = new Vector2 (transform.localScale.x, 0) * speed;
}
else if(Mathf.RoundToInt(transform.localEulerAngles.z) == 180){
clone.rigidbody2D.velocity = new Vector2 (0, transform.localScale.y) * speed;
}
else if(Mathf.RoundToInt(transform.localEulerAngles.z) == 270){
clone.rigidbody2D.velocity = new Vector2(transform.localScale.x, 0) * speed * -1;
}
}
}
onShoot()方法被称为动画的事件。
你们有什么建议吗?
的“InvokeRepeating()”方法也可用于这种情况。 – 2015-04-03 21:01:25