Skip to content
Permalink
1541fe9796
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
107 lines (88 sloc) 2.98 KB
using UnityEngine;
using System.Collections;
public class PlayerControls : MonoBehaviour {
//Declarations
//Player
public GameObject player;
//Player Location
public float xPos;
public float yPos;
public Vector3 playerLocation;
public Vector3 playerAngle = new Vector3(270, 0, 0);
//Counting shit
public float distance = 0.25f;
//Shooting Objects
public GameObject playerBullet;
public GameObject leftCanon;
public GameObject rightCanon;
public Vector3 posRightCanon;
public Vector3 posLeftCanon;
public Rigidbody projectile;
public GameObject leftBullet;
public GameObject rightBullet;
public float thurst = 15.0f;
// Use this for initialization
void Awake()
{
xPos = 0.0f;
yPos = -5.0f;
}
void Start ()
{
transform.position = playerLocation;
}
// Update is called once per frame
void Update ()
{
if (transform.eulerAngles != playerAngle)
transform.eulerAngles = playerAngle;
//Movement------------------------------------------------------------------------------------------------------------
//Left
if (Input.GetKey(KeyCode.A))
{
if (xPos >= -17)
{
xPos = xPos - distance;
}
}
//Right
if (Input.GetKey(KeyCode.D))
{
if (xPos <= 16)
{
xPos = xPos + distance;
}
}
//Up
if (Input.GetKey(KeyCode.W))
{
if (yPos <= 11)
{
yPos = yPos + distance;
}
}
//Down
if (Input.GetKey(KeyCode.S))
{
if (yPos >= -5)
{
yPos = yPos - distance;
}
}
//Player Location Change ----------------------------------
playerLocation = new Vector3(xPos, yPos, 5.0f);
transform.position = playerLocation;
//Shooting-------------------------------------------------------------------------------------------------------------------------------------------
//Canon positions
posLeftCanon = new Vector3(leftCanon.transform.position.x, leftCanon.transform.position.y + 0.5f, leftCanon.transform.position.z);
posRightCanon = new Vector3(rightCanon.transform.position.x + 1.21f, rightCanon.transform.position.y + 0.5f, rightCanon.transform.position.z);
//Spawn Bullets
if (Input.GetKeyDown(KeyCode.Space))
{
leftBullet = (GameObject) Instantiate(playerBullet, posLeftCanon, transform.rotation);
iTween.MoveTo(leftBullet, new Vector3(leftBullet.transform.position.x, leftBullet.transform.position.y + 20, 5), 1);
rightBullet = (GameObject)Instantiate(playerBullet, posRightCanon, transform.rotation);
iTween.MoveTo(rightBullet, new Vector3(rightBullet.transform.position.x, rightBullet.transform.position.y + 20, 5), 1);
}
}
}