-
-
Save anonymous/7d553b4229e0371c3f7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class MageFire : MonoBehaviour { | |
public GameObject projectile; | |
public float fireRate = 0.5F; | |
private float nextFire = 0.0F; | |
public float power = 0.0F; | |
private Vector3 mousePos; | |
public GameObject mageArm; | |
private float downTime; //internal time from when the key is pressed | |
private bool isHandled = false; | |
private float waitTime = 1.0f; //wait time befor reacting | |
private bool buttonDown = false; | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
RaycastHit hit; | |
//mousePos = camera.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y - camera.transform.position.z)); | |
//rigidbody.transform.eulerAngles = new Vector3(0,0,Mathf.Atan2((mousePos.y - transform.position.y), (mousePos.x - transform.position.x))*Mathf.Rad2Deg - 90); | |
//mousePos = Input.mousePosition; | |
// mousePos.y = -(transform.position.x - Camera.mainCamera.transform.position.x); | |
// Vector3 worldPos = Camera.mainCamera.ScreenToWorldPoint(mousePos); | |
//float angle = Mathf.Atan2 (mousePos.x, mousePos.y) * Mathf.Rad2Deg; | |
// transform.rotation = Quaternion.Euler(0, -angle, 0); | |
mousePos = Camera.main.WorldToScreenPoint (transform.position); | |
Vector3 dir = Input.mousePosition - mousePos; | |
float angle = Mathf.Atan2 (dir.y, dir.x) * Mathf.Rad2Deg; | |
transform.rotation = Quaternion.AngleAxis (angle, Vector3.forward); | |
Quaternion q = Quaternion.AngleAxis (angle, Vector3.forward); | |
Vector3 fire = new Vector3 (q.eulerAngles.x, 0, 0); | |
Debug.DrawLine (mageArm.transform.position, mousePos, Color.blue); | |
//transform.LookAt(worldPos); | |
//transform.Rotate (Vector3.up, Mathf.PI); | |
//Debug.Log (Time.deltaTime); | |
if (Input.GetButtonDown("Fire1") && buttonDown == false) | |
{ | |
ButtonDown(); | |
} | |
else if (Input.GetButtonUp("Fire1") && buttonDown == true) | |
{ | |
ButtonUp(); | |
} | |
} | |
void ButtonDown(){ | |
buttonDown = true; | |
Debug.Log(buttonDown); | |
Debug.Log("A key or mouse click has been detected"); | |
power += Time.deltaTime * 10000; | |
} | |
void ButtonUp(){ | |
//Debug.Log(power); | |
nextFire = Time.time + fireRate; | |
GameObject crateClone = Instantiate(projectile, transform.position, transform.rotation) as GameObject; | |
crateClone.rigidbody.velocity = transform.TransformDirection(new Vector3(power,0,0)); | |
//crateClone.rigidbody.AddForce(fire * 1000); | |
Debug.Log ("Only outputs this line the first time"); | |
Debug.Log(power); | |
power = 0; | |
buttonDown = false; | |
Debug.Log(buttonDown); | |
Debug.Log(power); | |
Debug.Log ("Only outputs this line the first time"); | |
Destroy(crateClone, 5); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment