- Home /
Updating Bullet Force ONGUI
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;
}
}
Comment
Answer by Mint92 · May 02, 2014 at 02:17 PM
aha never mind. ive fixed it :)
void OnGUI()
{
Transform turret = transform.Find("TurretPivotControl");
TurretControl turretScript = (TurretControl)turret.GetComponent("TurretControl");
if (playerActive) GUI.Label(infoBox, "Player " + owner + " active");
else GUI.Label(infoBox, "Player " + owner + " inactive");
if (game.running)
{
GameObject player1 = game.getPlayer1();
GameObject player2 = game.getPlayer2();
if (player1 != null) GUI.Label(Player1livesBox, "Player1Lives: " + ((ShipController)player1.GetComponent("ShipController")).lives );
if (player2 != null) GUI.Label(Player2livesBox, "Player2Lives: " + ((ShipController)player2.GetComponent("ShipController")).lives );
if (player1 != null) GUI.Label(ForceBox, "ForceBox: " + turretScript.force);
if (player2 != null) GUI.Label(ForceBox, "ForceBox: " + turretScript.force);
}
}