Hey guys, how do i update my Ongui so when the player presses A and S it either decreases or increases the power.
using UnityEngine;
using System.Collections;
public class TurretControl : MonoBehaviour
{
public NetworkPlayer owner;
public float minForce, maxForce, forceIncrement;
public float force;
private int speed = 1;
public float maxRotationZ;
public float minRotationZ;
void Awake()
{
enabled = false;
}
void Start()
{
minForce = 100;
maxForce = 5000;
forceIncrement = maxForce * 0.05f;
force = (maxForce - minForce) / 2.0f;
maxRotationZ = 0.5f;
minRotationZ = -0.1f;
}
void OnGUI()
{
GUI.Button(new Rect (200, 70, 200, 20), minForce + maxForce + forceIncrement);
}
void Update ()
{
if(Input.GetKey(KeyCode.UpArrow))
{
//Debug.Log("z axis = " + transform.localRotation.z);
if (transform.localRotation.z <= maxRotationZ)
{
transform.Rotate(0, 0, Input.GetAxis("Vertical") * speed);
//Debug.Log("maxRotationZ:" + transform.rotation.z);
//Debug.Log("z axis = " + transform.localRotation.z);
}
}
if(Input.GetKey(KeyCode.DownArrow))
{
//Debug.Log("z axis = " + transform.localRotation.z);
if (transform.localRotation.z >= minRotationZ)
{
transform.Rotate(0, 0, Input.GetAxis("Vertical") * speed);
//Debug.Log("minRotationZ:" + transform.rotation.z);
//Debug.Log("z axis = " + transform.localRotation.z);
}
}
if(Input.GetKey(KeyCode.A))
{
force += (forceIncrement * Time.deltaTime);
if (force > maxForce) force = maxForce;
}
else if(Input.GetKey(KeyCode.S))
{
force -= (forceIncrement * Time.deltaTime);
if (force < minForce) force = minForce;
}
}
public float getForce()
{
return force;
}
}