using System.Collections;
public class PlayerControler : MonoBehaviour {
public float speed;
//to jump:
private bool jump;
private Rigidbody rb;
//to shoot:
public Rigidbody projectile;
public Transform shotpos;
public float shotForce;
// Use this for initialization
void Start () {
jump = true;
rb = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update () {
float x = Input.GetAxis ("Horizontal");
transform.Translate (x * Time.deltaTime * speed, 0, 0);
if (Input.GetKeyDown (KeyCode.LeftControl)) {
//fire projectile
Rigidbody shot = Instantiate(projectile, shotpos.position, Quaternion.identity) as Rigidbody;
shot.AddForce (shotpos.right * shotForce);
}
if (Input.GetKeyDown (KeyCode.Space)) {
//jump
//jump=true;
if(jump){
rb.AddForce (transform.up * 700);
jump = false;
}
}
}
void OnTriggerEnter(){
transform.position = new Vector3 (-9,0,0);
}
void OnCollisionEnter(Collision col){
if (col.gameObject.CompareTag ("floor")) {
jump = true;
}
}
}