Hi,
I want to active a “sand” after few seconds, just to respawn it.
I know it’s a lot easier to do by making second script but I can’t ,because there will be more those GameObjects in scene.
Thanks in advance.
Here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Collider2D))]
public class Sand : MonoBehaviour
{
Collider2D Collider;
public GameObject sand;
public float Time;
public GameObject dust;
void Start()
{
dust.SetActive(false);
sand.SetActive(true);
Collider = GetComponent<Collider2D>();
Collider.enabled = true;
}
void OnTriggerEnter2D(Collider2D colider)
{
if (colider.gameObject.tag == "Player")
{
StartCoroutine("TimeIsTicking");
++ScoreMenager.HScore;
Debug.Log("HighScore" + ScoreMenager.HScore);
Collider.enabled = false;
}
}
IEnumerator TimeIsTicking()
{
yield return new WaitForSeconds(Time);
dust.SetActive(true);
yield return new WaitForSeconds(0.6f);
sand.SetActive(false);
dust.SetActive(false);
}
}