i have this script that comes with the fps tutorial. i dont completely understand it so thats why i need ur help. it decreases from the bar when ever it comes in contact with something that has this script in it.
function OnTriggerEnter (col : Collider)
{
var player : MP = col.GetComponent(MP);
if (player)
{
player.DecreaseMP (10);
}
}
function Reset () {
if (collider == null)
gameObject.AddComponent(BoxCollider);
collider.isTrigger = true;
}
can anyone fix this script so that it only decreases from the bar when a button is pressed
if(input.GetButtonDown("fire3"))
function Update ()
{
if (Input.GetButtonDown("fire3"))
{
var player : MP = col.GetComponent(MP);
if (player)
{
player.DecreaseMP (10);
}
}
}
function Reset () {
if (collider == null)
gameObject.AddComponent(BoxCollider);
collider.isTrigger = true;
}
Completely errorless? Just saying it didn’t work is useless information to me just as much as my script suggestion may have been for you.
ya there was no errrors . but i dont think it will work. instead can u change this new script so that when i press a button. the gui texture bar will decrease
var maximumHitPoints = 100.0;
var maxmp = 100.0;
var healthGUI : GUITexture;
private var healthGUIWidth = 0.0;
private var gotHitTimer = -1.0;
function Awake () {
healthGUIWidth = healthGUI.pixelInset.width;
}
function DecreaseMP (damage : float) {
if (maxmp < 0.0)
return;
// Apply damage
maxmp -= damage;
// Are we dead?
if (maxmp < 0.0)
//Die();
print ("you died");
}
/*function Die () {
if (die)
AudioSource.PlayClipAtPoint(die, transform.position);
// Disable all script behaviours (Essentially deactivating player control)
var coms : Component[] = GetComponentsInChildren(MonoBehaviour);
for (var b in coms) {
var p : MonoBehaviour = b as MonoBehaviour;
if (p)
p.enabled = false;
}
LevelLoadFade.FadeAndLoadLevel(Application.loadedLevel, Color.white, 2.0);
} */
function LateUpdate () {
// Update gui every frame
// We do this in late update to make sure machine guns etc. were already executed
UpdateGUI();
}
function UpdateGUI () {
// Update health gui
// The health gui is rendered using a overlay texture which is scaled down based on health
// - Calculate fraction of how much health we have left (0...1)
var healthFraction = Mathf.Clamp01(maxmp / maximumHitPoints);
// - Adjust maximum pixel inset based on it
healthGUI.pixelInset.xMax = healthGUI.pixelInset.xMin + healthGUIWidth * healthFraction;
}