I am trying to generate different random values for the position of my game object whenever it is re-instantiated. For some reasons, it is not working. Can someone help to see what is wrong? (newPosition is the value that I hope it would be different everytime a new gameobject is generated.)
using UnityEngine;
using System.Collections;
public class KillObjectGenerator : MonoBehaviour
{
public float randomTimeDelay;
private Vector3 newPosition;
public float spawnTime = 3.0f;
public GameObject cloud;
public GameObject lightning;
private float randomX = Random.Range(-8.3f, 0.78f);
void Start()
{
randomTimeDelay = Random.Range(3f, 6f);
// Start calling the Spawn function repeatedly after a delay.
InvokeRepeating("Generator", randomTimeDelay, spawnTime);
}
void spawnNewPosition()
{
newPosition = new Vector3(randomX, 0.18f, 0);
}
void Generator()
{
Instantiate(cloud, newPosition, Quaternion.identity);
Instantiate(lightning, newPosition, Quaternion.identity);
Debug.Log("Spawned a kill object!");
}
}