//possibly combine this with random rocket positions. probably not though. //Script needs to instantiate the prefab for the rocket and then change its material. void Awake() { for (int i = 1; i <= PlayMenu._numberOfPlayers; i++) { GameObject prefab; GameObject instance = null; if (BoardGameHandler._rocketType[i - 1] == 0) { prefab = Resources.Load("Rocket") as GameObject; instance = GameObject.Instantiate(prefab, new Vector3(0, 0, 0), Quaternion.Euler(0, 0, 0)) as GameObject; } if (BoardGameHandler._rocketType[i - 1] == 1) { prefab = Resources.Load("UFO") as GameObject; } if (BoardGameHandler._rocketType[i - 1] == 2) { } if (BoardGameHandler._rocketType[i - 1] == 3) { } RocketBehavior rocket = instance.GetComponent <RocketBehavior>(); rocket._playerNumber = i; } }
void Start() { switch (PlayMenu._numberOfPlayers) { case 1: startingPositions.Add(0f); break; case 2: startingPositions.Add(-1f); startingPositions.Add(1f); break; case 3: startingPositions.Add(-2f); startingPositions.Add(0f); startingPositions.Add(2f); break; case 4: startingPositions.Add(-3f); startingPositions.Add(-1f); startingPositions.Add(1f); startingPositions.Add(3f); break; } for (int i = 0; i < PlayMenu._numberOfPlayers; i++) { RocketBehavior rocket = _rockets[i]; int rand = Random.Range(0, startingPositions.Count); rocket.transform.position = new Vector3(startingPositions[rand], 0.1f, 0); startingPositions.RemoveAt(rand); } }
void LaunchRocket() { lastLaunchTime = Time.time; float size = transform.localScale.x; Vector3 posShift = (transform.forward * size) + new Vector3(0f, 0f, 0f); Vector3 launchPosition = transform.position + posShift; GameObject rocket = Instantiate(RocketPrefab, launchPosition, Quaternion.identity); RocketBehavior newRocket = rocket.GetComponent <RocketBehavior>(); newRocket.OwnerID = ID; //same direction where mouse pointed newRocket.Initialize(currentWeaponStats, transform.forward); //add to storage Storage.Instance.AddToPool(rocket); }