using UnityEngine;
using System.Collections;

public class PlayerCannon : MonoBehaviour {
	
	string keycolour = "red";
	
	public GameObject hand;
	public GameObject cam;
	public AudioClip laserclip;
	void Update () {
		
		if(Input.GetKey(KeyCode.Q)){
			keycolour = "blue";
		}else if(Input.GetKey("2")){
			keycolour = "green";
		}else if(Input.GetKey(KeyCode.E)){
			keycolour = "red";
		}
		
		
		if(Input.GetKey(KeyCode.LeftShift)){
			for(int i=0; i<1;i++){
				GameObject laser = Instantiate(References.laserObj, hand.transform.position, Quaternion.Euler(-MouseLook.rotationY+Random.value*2-1,MouseLook.rotationX+Random.value*2-1,0)) as GameObject;
				Laser_S laser_script = laser.GetComponent(typeof(Laser_S)) as Laser_S;
				laser_script.SetColour(new LightColour(keycolour));
				laser_script.SetSource(hand, true);
				laser_script.SetLifetime(0.05f);
				audio.clip = laserclip;
				audio.pitch = 0.5f + Random.value*1f;
				audio.volume = 0.2f + Random.value * 0.2f;
				audio.Play();
			}
		}
		if(Input.GetKey(KeyCode.Space)){
		Quaternion q = Quaternion.Euler(-MouseLook.rotationY,MouseLook.rotationX,0);
		Matrix4x4 targetMatrix = Matrix4x4.TRS(cam.transform.position, q, Vector3.one); 
		Vector3 dir = targetMatrix.MultiplyPoint(new Vector3(0, 0, 1));
		dir -= cam.transform.position;
		RaycastHit hit;
		if(Physics.Raycast(cam.transform.position, dir, out hit)){
			hit.collider.gameObject.SendMessage("AirPush", SendMessageOptions.DontRequireReceiver);	
		}

		}
		
	}
}
