Hi, and sorry if this has already been answered, but I couldn’t find it. I have a weapon, a lightning field, and as it stands I can use it every second, and it does 3 damage (I think, haven’t tested the tag yet). I would like to set it up so that for the first second you can’t use it, from 1-2 seconds it’ll do 1 damage, 2-3 seconds it’ll do 2 damage, and from 3+ seconds if used it’ll do 3 damage.
var lightningShield : Rigidbody;
var spawnPoint;
var fireRate : float = 1.0;
var nextFireTime : float = 1.0;
function Update ()
{
if (Input.GetButtonDown("Fire2") && Time.time > nextFireTime)
{
nextFireTime = Time.time + fireRate;
var clone : Rigidbody;
clone = Instantiate(lightningShield, transform.Find("LightningShieldSpawn").transform.position, Quaternion.identity);
lightningShield.gameObject.tag = "dmg3";
}
}
Any help is greatly appreciated. How it works now is fine for me, but I wouldn’t mind adding that extra element that benefits those with more patience, which few people seem to have nowadays xD.
EDIT: Ok, I have a few ideas on how to fix the problem myself, just needed a day to think about it. The use of “int” values can set it up to work at certain times, also spawning multiple shields at once, all tagged to do 1 damage, could solve the problem. I still need to try these ideas, but if someone would like to help it would be appreciated.
When player pushes trigger, store current Time.time
When player releases trigger, subtract stored time from current Time.time
Result tells you how long the trigger was held
Something like this, maybe:
var triggerDownTime : float;
function Update ()
{
if (Input.GetButtonDown("Fire2"))
{
triggerDownTime = Time.time;
}
else if (Input.GetButtonUp("Fire2"))
{
var chargeTime = Time.time - triggerDownTime;
//you could do some branching, here
//but it looks like X seconds held gives X damage
//so we can just take the floor (round down)
var damage = Mathf.Floor(chargeTime);
}
}
That’s not a complete solution, of course, but it’s another option you could try. If you have anything that indicates charge steps to the player, code like this could make it really easy to use lerps.