Please help me searching the mistake I’ve made, follwing script doesn’t start to run. It on a gameobject but thre is nothing. Debug.Log should show me how far it comes, but I haven’t received on Debug.Log yet!
using UnityEngine.UI;
public class ObstacleSpawn : MonoBehaviour
{
/* float timeToObstacle;
float blinkTime = 0.5f;
float toObstacleMin = 5.1f;
float toObstacleMax = 60.1f;
public GameObject explosion;
public GameObject circle;
public GameObject player;
Vector3 circlePos;
float circleX;
float circleZ;
float obstacleRad;
float radMin;
float radMax;
private System.Random rnd;
public Text Log;
// Start is called before the first frame update
void Start()
{
rnd = new System.Random();
timeToObstacle = rnd.Next((int)toObstacleMin, (int)toObstacleMax);
radMin = 2f;
radMax = 20f;
obstacleRad = rnd.Next((int)radMin, (int)radMax);
circlePos = new Vector3(UnityEngine.Random.Range(-13.8f, 9.4f), 3.4f, UnityEngine.Random.Range(-8.5f, 13.6f));
}
// Update is called once per frame
void Update()
{
timeToObstacle -= Time.deltaTime;
if (timeToObstacle <= 3f)
{
Log.text = "Obstacle spawned!";
blinkTime -= Time.deltaTime;
Instantiate(circle, circlePos, Quaternion.identity);
circle.transform.localScale += obstacleRad;
if (blinkTime <= 0f)
{
circle.SetActive(false);
if(blinkTime <= -0.5f)
{
circle.SetActive(true);
blinkTime = 0.5f;
}
}
if(timeToObstacle <= 0f)
{
Instantiate(explosion, circlePos, Quaternion.identity);
if(Vector3.Distance(circlePos, GameObject.Find("Player").transform.position) <= obstacleRad){
SceneManager.LoadScene(0);
}
else
{
obstacleRad = rnd.Next((int)radMin, (int)radMax);
circlePos = new Vector3(UnityEngine.Random.Range(-13.8f, 9.4f), 3.4f, UnityEngine.Random.Range(-8.5f, 13.6f));
timeToObstacle = rnd.Next((int)toObstacleMin, (int)toObstacleMax);
Destroy(circle);
blinkTime = 0.5f;
Log.text = "Obstacle survived!";
}
}
}
} */
int amountObstacles;
float timeToObstacle;
public System.Random rnd;
public GameObject obstacle;
public Text Log;
void Start()
{
Debug.Log(1);
amountObstacles = rnd.Next(1, 20);
timeToObstacle = UnityEngine.Random.Range(10.0f, 60.0f);
Log.text = timeToObstacle + "s left to Wave";
Debug.Log(2);
}
void Update()
{
timeToObstacle -= Time.deltaTime;
Log.text = timeToObstacle + "s left to Wave";
Debug.Log(timeToObstacle + "s left to Wave");
if (timeToObstacle <= 0f)
{
for (int i = 0; i < amountObstacles; i++)
{
Vector3 _pos = new Vector3(UnityEngine.Random.Range(-13.8f, 9.4f), 3.4f, UnityEngine.Random.Range(-8.5f, 13.6f));
Instantiate(obstacle, _pos, Quaternion.identity);
}
Log.text = amountObstacles + " Obstacles spawned";
amountObstacles = rnd.Next(1, 20);
timeToObstacle = UnityEngine.Random.Range(10.0f, 60.0f);
}
}
}