Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Player : MonoBehaviour {
- private Transform TS;
- public int speed = 5;
- public GameObject Laser;
- // Use this for initialization
- void Start () {
- TS = transform;
- // Spawn point
- TS.position = new Vector3(0, -2.47f, 0);
- print (Screen.height);
- print (Screen.width);
- }
- // Update is called once per frame
- void Update () {
- TS.Translate (Vector3.up * Input.GetAxis("Vertical") * speed * Time.deltaTime);
- TS.Translate (Vector3.right * Input.GetAxis("Horizontal") * speed * Time.deltaTime);
- //Wrap the player.
- if(TS.position.x > 11.25f) {
- TS.position = new Vector3(-11.25f, TS.position.y, TS.position.z);
- }
- else if(TS.position.x < -11.25f) {
- TS.position = new Vector3(11.25f, TS.position.y, TS.position.z);
- }
- //Have the spaceship fire a laser via the Spacebar.
- if (Input.GetKeyDown(KeyCode.Space)) {
- //Set laser position.
- Vector3 lpos = new Vector3(TS.position.x, TS.position.y+.5f, TS.position.z);
- //Instantiate laser.
- Instantiate(Laser, lpos, Quaternion.identity);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement