Advertisement
Guest User

Ch0nG - Player.cs

a guest
Aug 13th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Player : MonoBehaviour {
  5.  
  6.     private Transform TS;
  7.     public int speed = 5;
  8.     public GameObject Laser;
  9.  
  10.     // Use this for initialization
  11.     void Start () {
  12.  
  13.         TS = transform;
  14.        
  15.         // Spawn point
  16.         TS.position = new Vector3(0, -2.47f, 0);
  17.         print (Screen.height);
  18.         print (Screen.width);
  19.     }
  20.    
  21.     // Update is called once per frame
  22.     void Update () {
  23.         TS.Translate (Vector3.up * Input.GetAxis("Vertical") * speed * Time.deltaTime);
  24.         TS.Translate (Vector3.right * Input.GetAxis("Horizontal") * speed * Time.deltaTime);
  25.  
  26.     //Wrap the player.
  27.         if(TS.position.x > 11.25f) {
  28.             TS.position = new Vector3(-11.25f, TS.position.y, TS.position.z);
  29.         }
  30.  
  31.         else if(TS.position.x < -11.25f) {
  32.             TS.position = new Vector3(11.25f, TS.position.y, TS.position.z);
  33.         }
  34.  
  35.     //Have the spaceship fire a laser via the Spacebar.
  36.  
  37.         if (Input.GetKeyDown(KeyCode.Space)) {
  38.             //Set laser position.
  39.             Vector3 lpos = new Vector3(TS.position.x, TS.position.y+.5f, TS.position.z);
  40.  
  41.             //Instantiate laser.
  42.             Instantiate(Laser, lpos, Quaternion.identity);
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement