- Home /
Calling Different numbers one after another
Hello, okay so what im trying to do is make a attack code that will randomize attack points(Attack points = how much life is lost) from what i gathered and already tried i using the Random.Range,, that just takes random numbers off i didn't want this i wanted something such as when the first hit is like -10 life, then the next -5 life, and so on, i was thinking of an array of numbers been called one after each other giving the effect of random life loss, without it actually been random, basicly so i have control of how much (LifePoints) i lose, i wouldn't know where to start, here is the code im using,
using UnityEngine;
using System.Collections;
public class Enemyattack : MonoBehaviour { public GameObject target; public float attackTimer; public float coolDown;
// Use this for initialization
void Start ()
{
attackTimer = 0;
coolDown = 2.0f;
}
// Update is called once per frame
void Update ()
{
if(attackTimer > 0)
attackTimer -= Time.deltaTime;
if(attackTimer < 0)
attackTimer = 0;
if(attackTimer ==0){
Attack();
attackTimer = coolDown;
}
}
private void Attack(){
float distance = Vector3.Distance(target.transform.position, transform.position);
Vector3 dir = (target.transform.position - transform.position).normalized;
float direction = Vector3.Dot(dir, transform.forward);
if(distance < 4){
if(direction > 0){
Health eh = (Health)target.GetComponent("Health");
eh.AddjustCurrentHealth(-10);
}
}
}
}
If anyone could help please feel free to :)
Thanks
Answer by TheLedworks · Mar 29, 2012 at 07:34 PM
Easiest way to do that i rekon is to set a hitCounter and then 0 it at the end of combat so....
private int hitCounter = 0;
if(hitEnemy)
{
dmg = 10 += -hitCounter;
if(hitCounter < max) //max it out at 5 to stop it going any lower
hitCounter++;
}
//1st hit will do 10, then 9, then 8 e.c.t
yes, dont forget to set hitCounter to 0 if out of combat
Your answer
Follow this Question
Related Questions
Sniper Zoom!!! 1 Answer
Activating Audio When Hitting a collider 2 Answers
Code Error!!!! 2 Answers
activating a box using a GUI button 1 Answer
Delaying GUITexture!!! 3 Answers