Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma strict
- // =========================================================================================== \\
- // left = 0
- // right = 1
- private var direction : int = 0;
- private var thePlayer : GameObject;
- private var doForce : boolean;
- private var collisionCooldown : boolean;
- // =========================================================================================== \\
- function Start ()
- {
- // grab player
- thePlayer = GameObject.Find("Player");
- // if player is facing right
- if(thePlayer.transform.localScale.x < 0)
- {
- // direction to move is right
- direction = 1;
- }
- }
- // called every tick
- function Update()
- {
- if(direction == 0)
- {
- MoveLeft();
- }
- else if(direction == 1)
- {
- MoveRight();
- }
- CheckCollision();
- }
- // When colliding with an object
- function OnTriggerEnter(obj : Collider)
- {
- Debug.Log("Entering.. ");
- // not a palyer who touched it
- if(obj.gameObject.tag != "Player")
- {
- return;
- }
- // add prize points
- GameObject.Find("GameManager").GetComponent(StatsScript).Prize();
- // make mario bigger
- SizeUp();
- Destroy(gameObject);
- }
- // =========================================================================================== \\
- // Move the mushroom right
- function MoveRight()
- {
- // move to the right
- transform.Translate(Vector3.right * Time.deltaTime * 2.0F);
- }
- // Move the mushroom left
- function MoveLeft()
- {
- // move to the left
- transform.Translate(Vector3.left * Time.deltaTime * 2.0F);
- }
- // Check for walls, floors, ceilings which affect mushroom's movement
- function CheckCollision()
- {
- /*
- if(Physics.Raycast(transform.position, Vector3.right, 1.0))
- {
- direction = 0;
- }
- else if(Physics.Raycast(transform.position, Vector3.left, 1.0))
- {
- direction = 1;
- }
- */
- // if nothing below the mushroom
- if(!Physics.Raycast(transform.position, Vector3.down, 0.6))
- {
- // apply gravity
- gameObject.rigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ;
- }
- // floor below mushroom
- else
- {
- // no gravity (so it doesn't fall through floor)
- gameObject.rigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ;
- }
- }
- // =========================================================================================== \\
- function SizeUp()
- {
- }
- // =========================================================================================== \\
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement