Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System;
- public class OrbControl : MonoBehaviour
- {
- int currentOrb = 0;
- int maxOrbs = 3;
- public Transform[] spawnPos;
- public GameObject airOrb;
- public GameObject fireOrb;
- public GameObject waterOrb;
- public bool allowOrbit = false; // if set to true then orbiting functionality needs to be added
- public bool overRideCurrentOrb = false; // if set to true then "currentOrb" will not be used
- public List<GameObject> orbs = new List<GameObject>();
- void Start()
- {
- if (maxOrbs < spawnPos.Length)
- {
- maxOrbs = spawnPos.Length;
- }
- }
- void Update()
- {
- if (Input.GetKeyDown ("q") && currentOrb < maxOrbs)
- {
- spawnAirOrb ();
- }
- if (Input.GetKeyDown ("w") && currentOrb < maxOrbs)
- {
- spawnFireOrb ();
- }
- if (Input.GetKeyDown ("e") && currentOrb < maxOrbs)
- {
- spawnWaterOrb ();
- }
- }
- void spawnAirOrb()
- {
- spawnOrb(airOrb, 0);
- }
- void spawnFireOrb()
- {
- spawnOrb(fireOrb, 1);
- }
- void spawnWaterOrb()
- {
- spawnOrb(waterOrb, 2);
- }
- void spawnOrb(GameObject orb, int index)
- {
- if (orb != null)
- {
- if (!overRideCurrentOrb)
- {
- index = currentOrb;
- }
- GameObject oldOrb = GameObject.Find(orb.name + "(Clone)");
- Vector3 position = spawnPos [index].position;
- Quaternion rotation = spawnPos [index].rotation;
- if (orbs.Count == maxOrbs)
- {
- for (int i = 0; i < orbs.Count; i++)
- {
- if (((!allowOrbit) && (orbs[i].transform.position == position)) ||
- ((allowOrbit) && (orbs[i] != null)))
- {
- oldOrb = orbs[i];
- orbs.RemoveAt(i);
- position = oldOrb.transform.position;
- rotation = oldOrb.transform.rotation;
- break;
- }
- }
- }
- if (oldOrb != null)
- {
- bool destroyOrb = (oldOrb.transform.position == position);
- if (allowOrbit)
- {
- // if orbiting is allowed then set the position and rotation values to the current object
- position = oldOrb.transform.position;
- rotation = oldOrb.transform.rotation;
- }
- if (destroyOrb)
- {
- Destroy(oldOrb);
- }
- }
- GameObject spawnedOrb = (GameObject)Instantiate (orb, position, rotation);
- orbs.Add(spawnedOrb);
- currentOrb++;
- if (currentOrb >= maxOrbs)
- {
- currentOrb = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement