Im trying to get this script to wait for 10 seconds before reading the rest of the script and the script is mainly based on the OnCollisionEnter2D but no matter how i write the IEnumerator into the script it gives me several errors one of the errors are the variable “wait” is declared but never used. the other error is, the body of GrowPowerup.OnCollisionEnter2D(Collision2D) cannot be an iterator block because “void” is not an iterator interface type.
i got to admit im confused here so it doesnt like that oncollision is a void and it doesnt recognize the name of the IEnumerator.
also it repeats the void error 3 times when hovered over in visual studio if that matters.
using UnityEngine;
using System.Collections;
public class GrowPowerup : MonoBehaviour
{
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
float lifetime = 20;
float timeofdying = Time.deltaTime;
if (lifetime < timeofdying)
{
Destroy(gameObject);
}
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Player")
{
StartCoroutine("Wait");
IEnumerator Wait
{
GameObject.Find("Player").transform.localScale = new Vector3(5, 5, 5);
Debug.Log("Grow" + Time.time);
Destroy(GetComponent<Rigidbody2D>());
Destroy(GetComponent<PolygonCollider2D>());
Destroy(GetComponent<SpriteRenderer>());
//float currenttime = Time.deltaTime;
//float executetime = 10;
//if (currenttime == executetime)
yield return new WaitForSeconds(10);
GameObject.Find("Player").transform.localScale = new Vector3(3, 3, 3);
Debug.Log("Shrink:" + Time.time);
Destroy(gameObject);
}
}
}
/*IEnumerator StartWait()
{
yield return StartCoroutine(Wait());
}
IEnumerator Wait()
{
yield return new WaitForSeconds(10);
GameObject.Find("Player").transform.localScale = new Vector3(3, 3, 3);
Debug.Log("Shrink:" + Time.time);
Destroy(gameObject);
}
*/
}