I know that i need to use IEnumerator MyMethod() and make a coroutine in order to make a script wait for seconds and then do something, but i can’t do this inside my script =\
So, i have a OnCollision void and i wanted to use wait for seconds on it, like:
void OnCollisionEnter(Collision collision)
{
Wait 2 seconds
Do everything that i want
}
But i can’t. I am having multiple problems, such as “this thing shouldn’t be here”, “you can’t do this” and all. I have read the docs about this a lot of times but this just doesn’t work.
Here is my script:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class EAimSys : MonoBehaviour //This is my Enemy script. As it doesn't have any mouse or keyboard, i need to use the WFS code.
{
bool Click = false;
bool target = false;
public float fireRate = 0.5F;
private float nextFire = 0.0F;
public GameObject Flash;
public Animator anim;
void OnCollisionEnter(Collision collision)
{
{
if (collision.gameObject.tag == "Player") //Here is where i want to start.
//I wanted to use the wait for seconds code in here, so everything below this would need to wait x seconds before happening.
//Why? Because otherwise my enemy would kill me instantly and i don't have enough experience to do anything more complicated than this.
anim.SetTrigger("Shoot");
AudioSource audio = GetComponent<AudioSource>();
audio.Play();
Flash.SetActive(true);
Debug.Log("Player Hit!");
}
}
void OnCollisionExit(Collision collision)
{
{
if (collision.gameObject.tag == "Enemy")
Flash.SetActive(false);
}
}
}