Do it one tine only please help.

i have a problem with my script. im making a tower defence game but i got a problem with life of the monster…
target2 is a gameobject(my cannonball) monsterPos i my monsters position(vector3)
point1 is Cannonball start position.
Life is my monsters life.(int = 200).
TowerCannonStats is my cannons damage (int = 50).

if(target2.transform.position == (MonsterPos)){
target2.transform.position = point1;
if(target1.Life >0){
target1.Life -= target.TowerCannonStats;
}
}

the problem is.i need TowerCannonStats only take 50 from Life. but it take 50 again and again. 1000000 times Each sec… how to i say it only shell do it one time…

I assume you do it on c#?

private bool m_wasDamaged = false;

if ( m_wasDamaged == false  target1.Life > 0 )
{
   target1.Life = target.TowerCannonStats;
   m_wasDamaged = true;
}

This way it does it only 1x as long as the object lives.
If you want another behaviour I need more infos how often the Game shall damage the target.
HtH
regards

in which function are you using this script ? update ? OnTriggerEnter ?..

Depends on what you want to do and how you do it. I have not enough Information to tell you this.

update

var Monster : Transform;
var MonsterPos : Vector3;
var point1 : Vector3;
var target : TowerStats;
var target2 : GameObject;
var target1 :move;
var duration :float = 100.0;
private var startTime : float;
var speed = 6.0;
var Delay = 15.0;
var i;

function Start () {

while (true) {
i = Mathf.Repeat(Time.time * speed, Delay);
yield;
}
}

function Update () {
MonsterPos = Monster.transform.position;
point1 = transform.position;
if(Vector3.Distance(Monster.transform.position, transform.position) <=target.TowerRangedStats){
var x = Input.GetAxis(“Horizontal”) * Time.deltaTime *-1;
transform.RotateAround(Vector3(0, -512, 0), Vector3.up, x);
transform.LookAt(Monster);
transform.eulerAngles.x = 0;
transform.eulerAngles.z = 0;
target2.transform.position = Vector3.Lerp(point1, Monster.position, i);
}
if(target2.transform.position == (MonsterPos)){
target2.transform.position = point1;
if(target1.Life >0){
target1.Life -= target.TowerCannonStats;
}
}
}

this is my full script

the update function gets called every frame so once the ‘if’ statement is valid, it will get called every frame.

ty alot