Advertisement
Guest User

Untitled

a guest
Aug 1st, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.20 KB | None | 0 0
  1. import UnityEngine;
  2. import System.Collections;
  3. import System;
  4.  
  5.  
  6. var yvel: float;
  7. var holdY: float;
  8. public var wepMgr: GameObject;
  9.  
  10. public var myLight : GameObject;
  11. var cameraA : GameObject;
  12. public static var paused = false;
  13. public var timedilation_on = false;
  14. public var turnnotstrafe = false;
  15. public var flying = false;
  16. public var jump = false;
  17. public var onGround = false;
  18.  
  19. public var running = true; // this is for auto running
  20. public var sprinting = false; //this is for the stamina draining sprint
  21. public var crouched = false;
  22. public var staminaRegen = false; //whether you're regenning stamina
  23. public var staminaRegenRate: int = 20;
  24. public var staminaDrainRate: int = 10;
  25.  
  26. public var myFont : Font;
  27. public var pic : Texture ;
  28. public var moveSpeed: float;
  29. public var runSpeed: float;
  30. public var sprintSpeed: float;
  31. private var speed = moveSpeed;;
  32. public var gravity = 1;
  33. public var jumpspeed = 1;
  34. private var yvelocity = 0;
  35. private var lightmapint;
  36. public var titleStyle4 : GUIStyle = new GUIStyle();
  37. public var levelTitleStyle : GUIStyle = new GUIStyle();
  38. public var lvlSubtitle : GUIStyle = new GUIStyle();
  39. var timeSymbol: Texture2D; // The time symbol seen by the time manager.
  40. var timeLevel: Texture2D; // The time level, represented by a blue bar defined in this Texture2D.
  41. var timeLevelBack: Texture2D; // A background panel that does not change so that one can compare current time with time possible.
  42. var pauseBack: Texture2D;
  43. var fullScreenPauseBack: GUIStyle = new GUIStyle();
  44. var backArrowStyle: GUIStyle = new GUIStyle();
  45. public var blueTimeBar = new GUIStyle();
  46.  
  47. var floorCollider: GameObject;
  48.  
  49. public var slowmotion : float;
  50. public var levelSecondName = "";
  51. var timeMod = 1;
  52. public var dilatorEnergy = 100;
  53. var refill = false;
  54. var regening = false;
  55. var draining = false;
  56.  
  57. var stamina: float = 100; //player stamina out of 100
  58.  
  59. public static var locked: System.Boolean = false;
  60.  
  61. var pausemain = false;
  62. var pausedobjectives = false;
  63. var pausedskills = false;
  64. var pausedcontrols = false;
  65. var pausedsettings = false;
  66.  
  67. // An actually-helpful label, we see that this is what dictates the showing of the first controls page.
  68. var helpImage1: Texture2D;
  69. var help1Style: GUIStyle = new GUIStyle();
  70. help1Style.normal.background = helpImage1;
  71.  
  72. // Also an actually-helpful label, we see that this is what dictates the showing of the second controls page.
  73. var helpImage2: Texture2D;
  74. var help2Style: GUIStyle = new GUIStyle();
  75. help2Style.normal.background = helpImage2;
  76.  
  77. var transparentGrayStyle: GUIStyle = new GUIStyle();
  78.  
  79.  
  80. // The code that dictates the texture and GUIStyle of the button that returns one to the main menu.
  81. var returnToMenu: Texture2D;
  82. var returnToMenuStyle: GUIStyle = new GUIStyle();
  83. returnToMenuStyle.normal.background = returnToMenu;
  84. returnToMenuStyle.font = myFont;
  85. returnToMenuStyle.fontSize = 40;
  86.  
  87. // The code that dictates the texture and GUIStyle of the button that takes one to the next page of controls in said menu.
  88. var nextPage: Texture2D;
  89. var nextPageStyle: GUIStyle = new GUIStyle();
  90. nextPageStyle.normal.background = nextPage;
  91. nextPageStyle.font = myFont;
  92. nextPageStyle.fontSize = 40;
  93.  
  94. var ctrlScreenTwo = false;
  95. var showinghelp = false;
  96.  
  97. function OnNetworkInstantiate (msg : NetworkMessageInfo)
  98. {
  99. if(!networkView.isMine)
  100. enabled=false;
  101. }
  102.  
  103. // Use this for initialization
  104. function Start ()
  105. {
  106.  
  107. if(flying)
  108. {
  109. rigidbody.useGravity = false;
  110. collider.enabled = false;
  111. }
  112.  
  113. titleStyle4.font = myFont;
  114. titleStyle4.fontSize = 28;
  115.  
  116.  
  117.  
  118. Screen.showCursor = false;
  119. paused = false;
  120. pausemain = false;
  121. pausedobjectives = false;
  122. pausedskills = false;
  123. pausedcontrols = false;
  124. pausedsettings = false;
  125.  
  126. //default time settings
  127. Time.timeScale = 1;
  128. Time.fixedDeltaTime = 0.02f;
  129.  
  130. myLight.GetComponent("Light").light.enabled = false;
  131.  
  132. speed = moveSpeed;
  133. }
  134.  
  135.  
  136. // Update is called once per frame
  137. function Update ()
  138. {
  139.  
  140. /*
  141. * Basic cameraA control forward, back, left right
  142. */
  143.  
  144. var alpha = 0.1;
  145. var beta = alpha * 20;
  146.  
  147.  
  148.  
  149. if(Input.GetButtonDown("Pause") && !locked)
  150. {
  151. if(!paused) //pause the game if it isn't already
  152. {
  153. paused = true;
  154. pausemain = true;
  155. Time.timeScale = 0;
  156. //Time.fixedDeltaTime = 0;
  157. Screen.showCursor = true;
  158. Screen.lockCursor = false;
  159. wepMgr.active = false;
  160. }
  161. else //unpause the game if it is paused
  162. {
  163. paused = false;
  164. Screen.showCursor = false;
  165. Screen.lockCursor = true;
  166. wepMgr.active = true;
  167. if(timedilation_on)
  168. {
  169. Time.timeScale = slowmotion;
  170. Time.fixedDeltaTime = slowmotion * 0.02f;
  171. }
  172. else
  173. {
  174. Time.timeScale = 1;
  175. Time.fixedDeltaTime = 0.02f;
  176. }
  177. }
  178. }
  179. if(!paused)
  180. {
  181. yvel = rigidbody.velocity.y;
  182. if(flying)
  183. {
  184. dilatorEnergy = 100;
  185. }
  186.  
  187. if(rigidbody.velocity.y > -0.5 && rigidbody.velocity.y < 0.5)
  188. {
  189. jump = false;
  190. }
  191.  
  192. Screen.lockCursor = true;
  193. if (timedilation_on == true)
  194. {
  195. rigidbody.useGravity = false;
  196. if(!flying)
  197. rigidbody.velocity.y -= 9.81*(1/Time.timeScale)*(1/Time.timeScale)* Time.deltaTime;
  198. if (dilatorEnergy > 0)
  199. {
  200. if (draining == false)
  201. {
  202. subtEnergyRate(80);
  203. draining = true;
  204. regening = false;
  205. }
  206. }
  207. else
  208. {
  209. timeMod = 1;
  210. var holdVel: Vector3 = rigidbody.velocity * Time.timeScale;
  211. Time.timeScale = 1;
  212. Time.fixedDeltaTime = 0.02f;
  213. rigidbody.velocity = holdVel;
  214. refill = true;
  215. timedilation_on = false;
  216. wepMgr.SendMessage("Slowmo", false);
  217. }
  218. }
  219. if (timedilation_on == false)
  220. {
  221. if(!flying)
  222. rigidbody.useGravity = true;
  223. if (dilatorEnergy < 100)
  224. {
  225. if (regening == false)
  226. {
  227. addEnergyRate(5);
  228. regening = true;
  229. draining = false;
  230. }
  231.  
  232. }
  233.  
  234. }
  235. if(Input.GetButtonDown("Slowmo"))//This is the slow-mo key
  236. {
  237. var slow = slowmotion;
  238. if(timedilation_on == false)
  239. {
  240. timeMod = 1/(slow);
  241. var holdVel3 = rigidbody.velocity;
  242. Time.timeScale = slow;
  243. Time.fixedDeltaTime = slow * 0.02f;
  244. rigidbody.velocity = holdVel3 * 1/Time.timeScale;
  245. timedilation_on = true;
  246. wepMgr.SendMessage("Slowmo", true);
  247. }
  248. else
  249. {
  250. timeMod = 1;
  251. var holdVel2: Vector3 = rigidbody.velocity * Time.timeScale;
  252. Time.timeScale = 1;
  253. Time.fixedDeltaTime = 0.02f;
  254. rigidbody.velocity = holdVel2;
  255. refill = true;
  256. timedilation_on = false;
  257. wepMgr.SendMessage("Slowmo", false);
  258. }
  259. }
  260. if(Input.GetButtonDown("Jump") || Input.GetKeyUp(KeyCode.Space))
  261. {
  262. if(flying == false && onGround)
  263. {
  264. jump = true;
  265. rigidbody.velocity.y = jumpspeed * 1/Time.timeScale;
  266. }
  267. }
  268.  
  269. if(Input.GetKeyDown(KeyCode.CapsLock)) //turn on running
  270. {
  271. if(running)
  272. {
  273. running = false;
  274. speed = moveSpeed;
  275. if(crouched)
  276. speed = LevelingScript.crouchSpeedModifier * speed;
  277. }
  278. else
  279. {
  280. running = true;
  281. speed = runSpeed;
  282. if(crouched)
  283. speed = LevelingScript.crouchSpeedModifier * speed;
  284. }
  285.  
  286. }
  287. if(Input.GetButtonDown("Run") || Input.GetKeyDown(KeyCode.LeftShift)) //sprint
  288. {
  289. if(!crouched && stamina > 0)
  290. {
  291. wepMgr.SendMessage("Sprinting", true, SendMessageOptions.DontRequireReceiver);
  292. sprinting = true;
  293. speed = sprintSpeed;
  294. }
  295. }
  296. else if(Input.GetButtonUp("Run") || Input.GetKeyUp(KeyCode.LeftShift))
  297. {
  298. wepMgr.SendMessage("Sprinting", false, SendMessageOptions.DontRequireReceiver);
  299. sprinting = false;
  300. if(!running)
  301. speed = moveSpeed;
  302. else
  303. speed = runSpeed;
  304. if(crouched)
  305. speed = LevelingScript.crouchSpeedModifier * speed;
  306. }
  307.  
  308.  
  309.  
  310.  
  311. //MOVEMENT starts here
  312. if(onGround || flying)
  313. {
  314. rigidbody.velocity.x = 0;
  315. rigidbody.velocity.z = 0;
  316. if(flying)
  317. rigidbody.velocity.y = 0;
  318. }
  319. if(Input.GetButton("Forward") || Input.GetAxis("Vertical") > 0)
  320. {
  321. if(flying)
  322. {
  323. rigidbody.velocity = cameraA.transform.forward * speed * (1/Time.timeScale);
  324. }
  325. else
  326. {
  327. if(onGround || flying)
  328. {
  329. var vecA : Vector3 = cameraA.transform.forward;
  330. vecA.y = 0;
  331. vecA.Normalize(); //sets the vectors size to one while keeping it's direction
  332. vecA = vecA * speed * timeMod; //multiply the vector by the forward speed
  333. rigidbody.velocity.x += vecA.x;
  334. rigidbody.velocity.z += vecA.z;
  335. }
  336. }
  337. }
  338. else if(Input.GetButton("Backward") || Input.GetAxis("Vertical") < 0)
  339. {
  340. if(flying)
  341. {
  342. rigidbody.velocity = cameraA.transform.forward * -1 * speed * (1/Time.timeScale);
  343. }
  344. else
  345. {
  346. if(onGround || flying)
  347. {
  348. var vec2 : Vector3 = cameraA.transform.forward;
  349. vec2.y = 0;
  350. vec2.Normalize();
  351. vec2 = vec2 * -1 * speed * timeMod;
  352. rigidbody.velocity.x += vec2.x;
  353. rigidbody.velocity.z += vec2.z;
  354.  
  355. }
  356. }
  357. }
  358. if(Input.GetButton("Left") || Input.GetAxis("Horizontal") < 0)
  359. {
  360. if(flying)
  361. {
  362. rigidbody.velocity -= cameraA.transform.right * speed * timeMod;
  363. }
  364. else
  365. {
  366. if(onGround)
  367. {
  368. var vec3 : Vector3 = cameraA.transform.right;
  369. vec3.y = 0;
  370. vec3.Normalize();
  371. rigidbody.velocity.x += vec3.x * -1 * speed * timeMod;
  372. rigidbody.velocity.z += vec3.z * -1 * speed * timeMod;
  373. }
  374. }
  375. }
  376. else if(Input.GetButton("Right") || Input.GetAxis("Horizontal") > 0)
  377. {
  378. if(flying)
  379. {
  380. rigidbody.velocity += cameraA.transform.right * speed * timeMod;
  381. }
  382. else
  383. {
  384. if(onGround)
  385. {
  386. var vec4 : Vector3 = cameraA.transform.right;
  387. vec4.y = 0;
  388. vec4.Normalize();
  389. rigidbody.velocity.x += vec4.x * speed * timeMod;
  390. rigidbody.velocity.z += vec4.z * speed * timeMod;
  391. }
  392.  
  393. }
  394. }
  395.  
  396. if( Input.GetButtonDown("Flashlight"))
  397. {
  398. myLight.GetComponent("Light").light.enabled = !myLight.GetComponent("Light").light.enabled;
  399. }
  400. if(Input.GetButtonDown("Crouch"))
  401. {
  402. var capsuleCollider = GetComponent(CapsuleCollider) as CapsuleCollider;
  403.  
  404. if(!crouched)
  405. {
  406. //change the speed
  407. speed = LevelingScript.crouchSpeedModifier * speed;
  408. capsuleCollider.height -= 1;
  409. cameraA.transform.localPosition.y -= 0.4;
  410. transform.position.y -= 0.4;
  411. floorCollider.transform.position.y += 0.4;
  412. crouched = true;
  413. }
  414. else
  415. {
  416. //check if there is space to uncrouch
  417. var rayhitC: RaycastHit;
  418. if(Physics.Raycast(transform.position, transform.up, rayhitC))
  419. {
  420. if(Vector3.Distance(rayhitC.point, transform.position) > 1)
  421. {
  422. //uncrouch
  423. if(running)
  424. speed = runSpeed;
  425. else
  426. speed = moveSpeed;
  427. capsuleCollider.height += 1;
  428. if(Math.Abs(rigidbody.velocity.y) < 0.1)
  429. {
  430. transform.position.y += 0.4;
  431. }
  432. cameraA.transform.localPosition.y += 0.4;
  433. floorCollider.transform.position.y -= 0.4;
  434. crouched = false;
  435. }
  436. }
  437. }
  438. }
  439. if(jump == false && rigidbody.velocity.y > 1 && flying == false) //fix time dilator bug
  440. {
  441. rigidbody.velocity.y = 1;
  442. }
  443. if(jump == true && rigidbody.velocity.y > 5 && flying == false)
  444. {
  445. rigidbody.velocity.y -= 0.5;
  446. }
  447.  
  448. if(sprinting && Math.Abs(rigidbody.velocity.x + rigidbody.velocity.z) > 0)
  449. {
  450. staminaRegen = false;
  451. if(stamina > staminaDrainRate * Time.deltaTime)
  452. {
  453. stamina -= staminaDrainRate * Time.deltaTime;
  454. }
  455. else
  456. {
  457. stamina = 0;
  458. wepMgr.SendMessage("Sprinting", false, SendMessageOptions.DontRequireReceiver);
  459. sprinting = false;
  460. if(!running)
  461. speed = moveSpeed;
  462. else
  463. speed = runSpeed;
  464. }
  465. }
  466. else if(stamina < 100)//regen stamina
  467. {
  468. regenStamina();
  469. if(staminaRegen)
  470. {
  471. if(stamina < 98)
  472. stamina += Time.deltaTime * staminaRegenRate;
  473. else
  474. stamina = 100;
  475. }
  476. }
  477.  
  478. }// end !paused statement
  479.  
  480.  
  481. }//end update
  482.  
  483.  
  484. function OnGUI ()
  485. {
  486. GUI.Label(Rect(300,0,200,20), "Time scale " + Time.timeScale);
  487.  
  488. if(paused && !locked)
  489. {
  490. if(pausemain)
  491. {
  492. GUI.Box( Rect( 0, 0, Screen.width, Screen.height), "", fullScreenPauseBack); // Le Background
  493.  
  494. GUI.Label( Rect( (Screen.width)-366, (Screen.height)-150, 366, 234), "", levelTitleStyle);
  495. //GUI.Label( Rect( (Screen.width/2)+30, (Screen.height/2) - 20, 300, 100), "Space isolated for objective system integration. To be implemented in further updates (date unknown). As always, thanks for playing!", lvlSubtitle);
  496.  
  497. GUI.Box( Rect( 5, 0, 200, Screen.height), "", transparentGrayStyle);
  498. if (GUI.Button( Rect( 5, (Screen.height) - 350, 369/2, 40)," Resume", titleStyle4))
  499. {
  500. paused = false;
  501. pausedmain = false;
  502. Screen.showCursor = false;
  503. Screen.lockCursor = true;
  504. if(timedilation_on)
  505. {
  506. Time.timeScale = slowmotion;
  507. Time.fixedDeltaTime = slowmotion * 0.02f;
  508. }
  509. else
  510. {
  511. Time.timeScale = 1;
  512. Time.fixedDeltaTime = 0.02f;
  513. }
  514. }
  515. if (GUI.Button(new Rect (5,(Screen.height) - 300,369/2, 40), " Restart", titleStyle4))
  516. {
  517. paused = false;
  518. pausedmain = false;
  519. Screen.showCursor = false;
  520. Screen.lockCursor = true;
  521. if(timedilation_on)
  522. {
  523. Time.timeScale = slowmotion;
  524. Time.fixedDeltaTime = slowmotion * 0.02f;
  525. }
  526. else
  527. {
  528. Time.timeScale = 1;
  529. Time.fixedDeltaTime = 0.02f;
  530. }
  531. Application.LoadLevel(Application.loadedLevel);
  532. }
  533. if (GUI.Button(new Rect( 5, (Screen.height) - 250, 369/2, 40)," Objectives", titleStyle4))
  534. {
  535. pausedobjectives = true;
  536. pausedmain = false;
  537. }
  538. if (GUI.Button(new Rect( 5, (Screen.height) - 200, 369/2, 40)," Skills", titleStyle4))
  539. {
  540. pausedskills = true;
  541. pausedmain = false;
  542. }
  543. if (GUI.Button(new Rect( 5, (Screen.height) - 150, 369/2, 40)," Controls", titleStyle4))
  544. {
  545. pausedcontrols = true;
  546. showinghelp = true;
  547. pausedmain = false;
  548. }
  549. if (GUI.Button(new Rect( 5, (Screen.height) - 100, 369/2, 40)," Settings", titleStyle4))
  550. {
  551. pausedsettings = true;
  552. pausedmain = false;
  553. }
  554. if (GUI.Button(new Rect( 5, (Screen.height) - 50, 369/2, 40)," Exit", titleStyle4))
  555. {
  556. Application.Quit();
  557. }
  558. /*if (GUI.Button(new Rect ((Screen.width/2)-40,(Screen.height / 2) - 20,80,20), "TOFU"))
  559. {
  560.  
  561. }*/
  562. }
  563.  
  564. if (pausedobjectives)
  565. {
  566. GUI.Label( Rect( 0, 0, Screen.width, Screen.height), "", fullScreenPauseBack); // Le Background
  567. GUI.Label( Rect( 50, 10, Screen.width, 36), "Objectives", levelTitleStyle);
  568. if(GUI.Button( new Rect(5, 10, 40, 36), "", backArrowStyle))
  569. {
  570. pausedobjectives = false;
  571. pausemain = true;
  572. }
  573. }
  574.  
  575. if (pausedskills)
  576. {
  577. GUI.Label( Rect( 0, 0, Screen.width, Screen.height), "", fullScreenPauseBack); // Le Background
  578. GUI.Label( Rect( 50, 10, Screen.width, 36), "Skills", levelTitleStyle);
  579. if(GUI.Button( new Rect(5, 10, 40, 36), "", backArrowStyle))
  580. {
  581. pausedskills = false;
  582. pausemain = true;
  583. }
  584.  
  585. }
  586.  
  587. if (pausedsettings)
  588. {
  589. GUI.Label( Rect( 0, 0, Screen.width, Screen.height), "", fullScreenPauseBack); // Le Background
  590. GUI.Label( Rect( 50, 10, Screen.width, 36), "Settings", levelTitleStyle);
  591. if(GUI.Button( new Rect(5, 10, 40, 36), "", backArrowStyle))
  592. {
  593. pausedsettings = false;
  594. pausemain = true;
  595. }
  596. }
  597. if (pausedcontrols)
  598. {
  599. GUI.Label( Rect( 0, 0, Screen.width, Screen.height), "", fullScreenPauseBack); // Le Background
  600. GUI.Label( Rect( 50, 10, Screen.width, 36), "Controls", levelTitleStyle);
  601. if(GUI.Button( new Rect(5, 10, 40, 36), "", backArrowStyle))
  602. {
  603. pausedcontrols = false;
  604. pausemain = true;
  605. }
  606.  
  607. if(showinghelp) { // The first screen of help shows (page one).
  608. GUI.Label ( Rect( ((Screen.width - helpImage1.width)/2), ((Screen.height - helpImage1.height)/2), helpImage1.width, helpImage1.height), "", help1Style);
  609. }
  610. }
  611.  
  612. }
  613. var myStyle = new GUIStyle();
  614. myStyle.font = myFont;
  615. if(!paused)
  616. {
  617.  
  618. GUI.Box(Rect(Screen.width - 426, 10, 400, 32),"");
  619.  
  620. // GUI.Box(new Rect(55, 40, dilatorEnergy, 32), "" + dilatorEnergy);
  621.  
  622.  
  623.  
  624. GUI.Box(Rect(Screen.width - 425, 12, dilatorEnergy * 4, 28), "", blueTimeBar);
  625. }
  626. if(!paused && timedilation_on)
  627. {
  628. var temp = new GUIStyle();
  629. temp.normal.background = pic;
  630. GUI.Box(Rect(0, 0, Screen.width, Screen.height), "", temp);
  631. }
  632. if(!paused)
  633. {
  634. GUI.Label(Rect(200, 0, 250, 20), "Stamina " + stamina);
  635. }
  636. }
  637.  
  638. function addEnergyRate(rate: float) {
  639. while(timedilation_on == false && dilatorEnergy<100)
  640. {
  641. yield WaitForSeconds(1/rate);
  642. dilatorEnergy += 1;
  643. }
  644. }
  645.  
  646. function subtEnergyRate(rate: float) {
  647. while(timedilation_on == true && dilatorEnergy>0)
  648. {
  649. yield WaitForSeconds(1/rate);
  650. dilatorEnergy -= 1;
  651. }
  652. }
  653.  
  654. function regenStamina()
  655. {
  656. if(staminaRegen == false) //make sure we aren't already regening
  657. {
  658. yield WaitForSeconds(3); //wait three seconds before regenning stamina
  659. staminaRegen = true;
  660. }
  661. }
  662.  
  663. function Lock()
  664. {
  665. paused = true;
  666. locked = true;
  667. transform.rigidbody.velocity = Vector3(0,0,0); //stop that motion pls
  668. Time.timeScale = 1;
  669. Time.fixedDeltaTime = 0.02f;
  670. Screen.showCursor = true;
  671. Screen.lockCursor = false;
  672. wepMgr.SendMessage("disableWeps");
  673. cameraA.SendMessage("setSensitivity", 0);
  674. }
  675.  
  676. function Unlock()
  677. {
  678. paused = false;
  679. locked = false;
  680. Screen.showCursor = false;
  681. Screen.lockCursor = true;
  682. Time.timeScale = 1;
  683. Time.fixedDeltaTime = 0.02f;
  684. wepMgr.SendMessage("enableWeps");
  685. cameraA.SendMessage("resetSensitivity");
  686. }
  687.  
  688. function OnGround(boolIn: System.Boolean)
  689. {
  690. onGround = boolIn;
  691. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement