I am currently learning the concepts of unity… so sorry if i have asked you something wrong. But i want to make my concepts clear. In my case i have one script in that i am instantiating bulletprefab and at the same time i want to generate sphere of the random color. so i have created prefab with different color which i am going to instantiate randomly. Now i want to change that prefab every time i shoot.
so in shooting script start() function again i need to to generate random prefab. so what can be the best way to avoid duplicate lines of code ??
code :
function Start () {
futureBubble = GameObject.Find("Sphere(FutureBubble)"); // Next bubble to be shoot
if(futureBubble != null)
{
random = Random.Range(0 , bubblePrefabs.Length - 1);
Instantiate(bubblePrefabs[random] , futureBubble.transform.position , Quaternion.identity);
}
}
function Update ()
{
var spawnPoint : GameObject = GameObject.Find("Bullet"); // Current Bullet Bubble to be shoot
if(Input.GetMouseButtonDown(0))
{
if(spawnPoint != null)
{
Instantiate(bulletSphere, spawnPoint.transform.position,spawnPoint.transform.rotation);
// here again i need another color prefab
}
}
}
Thanx for your support and help…