Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- //by gareth murfin www.garethmurfin.co.uk
- public class RSL_SwapBetweenACAndUFPS : MonoBehaviour {
- // Use this for initialization
- void Start () {
- }
- const int PLAY_MODE_FIRST_PERSON_POINT_AND_CLICK = 1;
- const int PLAY_MODE_FIRST_PERSON_SHOOTER = 2;
- int playMode = PLAY_MODE_FIRST_PERSON_POINT_AND_CLICK;
- string nameOfACguy = "HeroGaz1.5.0_PLAYMODE_AC"; //We use the name of this because it doesnt exist until we run the game an AC spawns him
- GameObject acGuy;
- public GameObject acEngine, UFPSGuy; // these ones we drag into inspector (mak sure UFPS guy is off in heirarchy)
- // Update is called once per frame
- void Update () {
- if (Input.GetKeyDown(KeyCode.F5))// TOGGLE PLAYER MODE (FP point n click or FP shooter)
- {
- /*
- In order to swap between UFPS and AC we need to do some work.
- They wont work together PERFECTLY, AC is designed for passive games without gun slinging, UFPS
- for fast paced shooting. But if we are careful they work almost perfectly. And we can have a mode
- to flip between AC (First person Point n click) and UFPS (First person shooter). This unfortunately has
- to be the way it is. But if we work it into the game properly, I see no issues. For example,
- we could have guns only come out at set moments, or rely on player to press key to flip out gun,
- when they need it.
- NOTE: For others levels we can do exactly this too, Or we can choose just to use a UFPS guy
- (for example if theres no pointing and clicking and its all hardcore action) or just an AC guy
- (for example when theres no killing to be done).
- KNOWN LIMITATION: I only copy position and rotation of the characters, cameras still dont appear EXACTLY the same yet
- TODO: fix so transition between UFPS guy and AC guy is not visible
- */
- switch(playMode)
- {
- case PLAY_MODE_FIRST_PERSON_POINT_AND_CLICK:
- Debug.Log("MOVE TO FIRST PERSON SHOOTER MODE");
- //turn off the AC guy
- if (acGuy==null)
- {
- acGuy = find(nameOfACguy);
- }
- acGuy.SetActive(false);
- //turn off the AC engine
- acEngine.SetActive(false);
- //turn on the UFPS guy
- UFPSGuy.SetActive(true);
- //put UFPS guy where AC guy was
- UFPSGuy.transform.position = acGuy.transform.position;
- UFPSGuy.transform.rotation = acGuy.transform.rotation;
- //update our state so we know what mode we are in
- playMode=PLAY_MODE_FIRST_PERSON_SHOOTER;
- break;
- case PLAY_MODE_FIRST_PERSON_SHOOTER:
- Debug.Log("MOVE TO FIRST PERSON POINT AND CLICK MODE");
- //turn off the UFPS guy
- UFPSGuy.SetActive(false);
- //turn on the AC engine
- acEngine.SetActive(true);
- //turn on the AC guy
- if (acGuy==null)
- {
- acGuy = find(nameOfACguy);
- }
- acGuy.SetActive(true);
- //put AC guy where UFPS guy was
- acGuy.transform.position = UFPSGuy.transform.position;
- acGuy.transform.rotation = UFPSGuy.transform.rotation;
- //update our state so we know what mode we are in
- playMode=PLAY_MODE_FIRST_PERSON_POINT_AND_CLICK;
- break;
- default:
- Debug.Log("UNKNOWN PLAY MODE! "+playMode);
- break;
- }
- }
- }
- private GameObject find(string s)
- {
- GameObject go = GameObject.Find(s);
- if (go==null)
- {
- Debug.Log("WARNING COULD NOT FIND "+s);
- }
- return go;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment