Advertisement
Guest User

Untitled

a guest
Oct 15th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. #pragma strict
  2.  
  3. // =========================================================================================== \\
  4.  
  5. // left = 0
  6. // right = 1
  7. private var direction : int = 0;
  8.  
  9. private var thePlayer : GameObject;
  10. private var doForce : boolean;
  11. private var collisionCooldown : boolean;
  12.  
  13. // =========================================================================================== \\
  14.  
  15. function Start ()
  16. {
  17. // grab player
  18. thePlayer = GameObject.Find("Player");
  19.  
  20.  
  21. // if player is facing right
  22. if(thePlayer.transform.localScale.x < 0)
  23. {
  24. // direction to move is right
  25. direction = 1;
  26. }
  27. }
  28.  
  29.  
  30. // called every tick
  31. function Update()
  32. {
  33.  
  34. if(direction == 0)
  35. {
  36. MoveLeft();
  37. }
  38. else if(direction == 1)
  39. {
  40. MoveRight();
  41. }
  42.  
  43.  
  44. CheckCollision();
  45. }
  46.  
  47.  
  48. // When colliding with an object
  49. function OnTriggerEnter(obj : Collider)
  50. {
  51. Debug.Log("Entering.. ");
  52.  
  53. // not a palyer who touched it
  54. if(obj.gameObject.tag != "Player")
  55. {
  56. return;
  57. }
  58.  
  59. // add prize points
  60. GameObject.Find("GameManager").GetComponent(StatsScript).Prize();
  61.  
  62. // make mario bigger
  63. SizeUp();
  64.  
  65. Destroy(gameObject);
  66. }
  67.  
  68.  
  69. // =========================================================================================== \\
  70.  
  71. // Move the mushroom right
  72. function MoveRight()
  73. {
  74. // move to the right
  75. transform.Translate(Vector3.right * Time.deltaTime * 2.0F);
  76. }
  77.  
  78.  
  79. // Move the mushroom left
  80. function MoveLeft()
  81. {
  82. // move to the left
  83. transform.Translate(Vector3.left * Time.deltaTime * 2.0F);
  84. }
  85.  
  86.  
  87. // Check for walls, floors, ceilings which affect mushroom's movement
  88. function CheckCollision()
  89. {
  90.  
  91. /*
  92. if(Physics.Raycast(transform.position, Vector3.right, 1.0))
  93. {
  94. direction = 0;
  95. }
  96. else if(Physics.Raycast(transform.position, Vector3.left, 1.0))
  97. {
  98. direction = 1;
  99. }
  100. */
  101.  
  102.  
  103.  
  104.  
  105.  
  106. // if nothing below the mushroom
  107. if(!Physics.Raycast(transform.position, Vector3.down, 0.6))
  108. {
  109. // apply gravity
  110. gameObject.rigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ;
  111. }
  112. // floor below mushroom
  113. else
  114. {
  115. // no gravity (so it doesn't fall through floor)
  116. gameObject.rigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ;
  117. }
  118.  
  119. }
  120.  
  121. // =========================================================================================== \\
  122.  
  123. function SizeUp()
  124. {
  125. }
  126.  
  127. // =========================================================================================== \\
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement