Advertisement
LeeMace

Move Left

Dec 2nd, 2022
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MoveLeft : MonoBehaviour
  6. {
  7.     private float speed = 25;
  8.     private PlayerController playerControllerScript;
  9.     private float leftBound = -15;
  10.     // Start is called before the first frame update
  11.     void Start()
  12.     {
  13.         playerControllerScript = GameObject.Find("Player").GetComponent<PlayerController>();
  14.     }
  15.  
  16.     // Update is called once per frame
  17.     void Update()
  18.     { //if the player hits ob the gme stops and the things stop moving
  19.         //obs move double speed if player is moving double speed
  20.         if (playerControllerScript.gameOver == false)
  21.         {
  22.             if (playerControllerScript.doubleSpeed)
  23.             {
  24.                 transform.Translate(Vector3.left * Time.deltaTime * (speed * 2));
  25.             }
  26.             else
  27.             {
  28.             transform.Translate(Vector3.left * Time.deltaTime * speed);
  29.             }
  30.         }
  31.         // destroys obstacles once they pass out of bounds
  32.         if (transform.position.x < leftBound && gameObject.CompareTag("Obstacle"))
  33.             {
  34.             Destroy(gameObject);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement