Guest User

Flip between UFPS and AC

a guest
Mar 25th, 2015
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. //by gareth murfin www.garethmurfin.co.uk
  5. public class RSL_SwapBetweenACAndUFPS : MonoBehaviour {
  6.  
  7. // Use this for initialization
  8. void Start () {
  9.  
  10. }
  11.  
  12.  
  13. const int PLAY_MODE_FIRST_PERSON_POINT_AND_CLICK = 1;
  14. const int PLAY_MODE_FIRST_PERSON_SHOOTER = 2;
  15. int playMode = PLAY_MODE_FIRST_PERSON_POINT_AND_CLICK;
  16.  
  17. 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
  18. GameObject acGuy;
  19.  
  20. public GameObject acEngine, UFPSGuy; // these ones we drag into inspector (mak sure UFPS guy is off in heirarchy)
  21.  
  22. // Update is called once per frame
  23. void Update () {
  24.  
  25.  
  26. if (Input.GetKeyDown(KeyCode.F5))// TOGGLE PLAYER MODE (FP point n click or FP shooter)
  27. {
  28. /*
  29. In order to swap between UFPS and AC we need to do some work.
  30. They wont work together PERFECTLY, AC is designed for passive games without gun slinging, UFPS
  31. for fast paced shooting. But if we are careful they work almost perfectly. And we can have a mode
  32. to flip between AC (First person Point n click) and UFPS (First person shooter). This unfortunately has
  33. to be the way it is. But if we work it into the game properly, I see no issues. For example,
  34. we could have guns only come out at set moments, or rely on player to press key to flip out gun,
  35. when they need it.
  36. NOTE: For others levels we can do exactly this too, Or we can choose just to use a UFPS guy
  37. (for example if theres no pointing and clicking and its all hardcore action) or just an AC guy
  38. (for example when theres no killing to be done).
  39.  
  40. KNOWN LIMITATION: I only copy position and rotation of the characters, cameras still dont appear EXACTLY the same yet
  41. TODO: fix so transition between UFPS guy and AC guy is not visible
  42. */
  43.  
  44. switch(playMode)
  45. {
  46. case PLAY_MODE_FIRST_PERSON_POINT_AND_CLICK:
  47. Debug.Log("MOVE TO FIRST PERSON SHOOTER MODE");
  48. //turn off the AC guy
  49. if (acGuy==null)
  50. {
  51. acGuy = find(nameOfACguy);
  52. }
  53. acGuy.SetActive(false);
  54. //turn off the AC engine
  55. acEngine.SetActive(false);
  56. //turn on the UFPS guy
  57. UFPSGuy.SetActive(true);
  58.  
  59. //put UFPS guy where AC guy was
  60. UFPSGuy.transform.position = acGuy.transform.position;
  61. UFPSGuy.transform.rotation = acGuy.transform.rotation;
  62.  
  63. //update our state so we know what mode we are in
  64. playMode=PLAY_MODE_FIRST_PERSON_SHOOTER;
  65. break;
  66. case PLAY_MODE_FIRST_PERSON_SHOOTER:
  67. Debug.Log("MOVE TO FIRST PERSON POINT AND CLICK MODE");
  68. //turn off the UFPS guy
  69. UFPSGuy.SetActive(false);
  70. //turn on the AC engine
  71. acEngine.SetActive(true);
  72. //turn on the AC guy
  73. if (acGuy==null)
  74. {
  75. acGuy = find(nameOfACguy);
  76. }
  77. acGuy.SetActive(true);
  78.  
  79. //put AC guy where UFPS guy was
  80. acGuy.transform.position = UFPSGuy.transform.position;
  81. acGuy.transform.rotation = UFPSGuy.transform.rotation;
  82.  
  83. //update our state so we know what mode we are in
  84. playMode=PLAY_MODE_FIRST_PERSON_POINT_AND_CLICK;
  85. break;
  86. default:
  87. Debug.Log("UNKNOWN PLAY MODE! "+playMode);
  88. break;
  89. }
  90. }
  91. }
  92.  
  93. private GameObject find(string s)
  94. {
  95. GameObject go = GameObject.Find(s);
  96. if (go==null)
  97. {
  98. Debug.Log("WARNING COULD NOT FIND "+s);
  99. }
  100. return go;
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment