Hello, I am trying to write a function which will create a visual vector on a rigidbody. Then this vector can be rotated with mouse. When vecotr rotation is finished a force is added to that rigidbody.
My code is not working and I’d like to hear tips and suggestions. Thanks in advance for your answers.
var arrowPrefab : GameObject;
var speed : int;
var forceMultiplyer : float;
private var arrowInstance : GameObject;
function Update () {
if (Input.GetMouseButton(1)) {
if (arrowInstance == null) {
arrowInstance = Instantiate(arrowPrefab, transform.position, Quaternion.identity);
}
else {
if (Input.GetMouseButton(0)) {
arrowInstance.transform.Rotate(0, 0, Input.GetAxis("Mouse Y") * Time.deltaTime * speed);
}
else {
arrowInstance.transform.Rotate(Vector3(Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"), 0) * Time.deltaTime * speed);
}
}
}
if (Input.GetMouseButtonUp(1)) {
if (arrowInstance != null) {
var forceVector : Vector3 = new Vector3(forceMultiplyer,
forceMultiplyer,
forceMultiplyer);
rigidbody.AddForce(arrowInstance.transform.rotation * forceVector);
Destroy(arrowInstance);
}
}
}