Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Player : MonoBehaviour {
  5.  
  6.     private Transform myTransform;
  7.  
  8.     public int playerSpeed = 5;
  9.  
  10.     //variable to reference prefab. prefab = gameObject (reusable)
  11.  
  12.     public GameObject Projectilefab;
  13.  
  14.     // Use this for initialization
  15.     void Start () {
  16.  
  17.         myTransform = transform;
  18.  
  19.         //Spawn Point
  20.         myTransform.position = new Vector3 (0, 3, -1);
  21.  
  22.     }
  23.    
  24.     // Update is called once per frame
  25.     void Update () {
  26.  
  27.         //Move the player left and right
  28.         myTransform.Translate (Vector3.right * playerSpeed * Input.GetAxis ("Horizontal") * Time.deltaTime);
  29.  
  30.         //Make the Player Wrap
  31.         if(myTransform.position.x > 9) {
  32.             myTransform.position = new Vector3(-9, myTransform.position.y, myTransform.position.z);
  33.         }
  34.         else if (myTransform.position.x < -9) {
  35.             myTransform.position = new Vector3(9, myTransform.position.y, myTransform.position.z);
  36.         }
  37.  
  38.         //Press the space bar to fire a lazer upward
  39.  
  40.         if (Input.GetKeyDown(KeyCode.Space)) {
  41.             //set position for lazer
  42.             Vector3 position = new Vector3(myTransform.position.x, myTransform.position.y, myTransform.position.z);
  43.             //fire projectile
  44.             Instantiate(Projectilefab, position, Quaternion.identity);
  45.         }
  46.  
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement