So like in the title i have this:
var prefab : GameObject;
var spawn : Transform;
var attackSpeed : float;
private var apd : float;
function Start()
{
apd = attackSpeed;
}
function FixedUpdate ()
{
if(Input.GetButtonDown("Fire1") && apd>=attackSpeed)
{
clone = Instantiate(prefab, spawn.position, spawn.rotation);
apd = 0;
}
if(apd<=attackSpeed)
{
apd += Time.deltaTime*1;
}
}
So it’s kinda like limit to the “attack speed” or instantiate cooldown and there is this code that doesn’t work
var abilityQ : int;
var abilityW : int;
var abilityE : int;
var abilityR : int;
var abilityQCooldown : int; var qCd : int;
var abilityWCooldown : int; private var wCd : int;
var abilityECooldown : int; private var eCd : int;
var abilityRCooldown : int; private var rCd : int;
var multipleArrowsArrow : GameObject;
var multipleArrowsSpawn : Transform;
function Start()
{
qCd = abilityQCooldown;
wCd = abilityWCooldown;
eCd = abilityECooldown;
rCd = abilityRCooldown;
}
function FixedUpdate ()
{
if(Input.GetKeyDown(KeyCode.Q) && qCd>=abilityQCooldown)
{
switch (abilityQ)
{
case 0: //No ability selected
Debug.Log("No Q Ability Chosen");
break;
case 1: //MultipleArrows
Instantiate(multipleArrowsArrow, multipleArrowsSpawn.position, multipleArrowsSpawn.rotation);
Instantiate(multipleArrowsArrow, multipleArrowsSpawn.position, new Vector3(multipleArrowsSpawn.rotation.x,multipleArrowsSpawn.rotation.y,multipleArrowsSpawn.rotation.z+10));
Instantiate(multipleArrowsArrow, multipleArrowsSpawn.position, new Vector3(multipleArrowsSpawn.rotation.x,multipleArrowsSpawn.rotation.y,multipleArrowsSpawn.rotation.z-10));
qCd = 0;
break;
}
}
if(qCd<=abilityQCooldown)
{
qCd += Time.deltaTime;
}
if(wCd<=abilityWCooldown)
{
wCd += Time.deltaTime*1;
}
if(eCd<=abilityECooldown)
{
eCd += Time.deltaTime*1;
}
if(rCd<=abilityRCooldown)
{
rCd += Time.deltaTime*1;
}
}
So I have 2 questions. Why does += Time.deltaTime work in the case no. 1 but not in case no. 2. Even if I put it in Update without IF statemant it still doesn’t count up like in case no. 1. It just would not go up after reseting it to 0 like a cooldown. Now there might be better ways to do “Cooldown spells” and stuff like that on the internet but since this is more like me learing the script im just curious to see what is wrong.
Secondly that part with Instantiate in case no. 2 where i add new vector3 blah blah rotation.z +10 it says that that is not a regular Unity Vector 3. I tried doing it with Eulers and Quanturnions but still had no luck. This is realy “itching” me since this is very basic script and yet I have next to no clue what I did wrong.
So if anyone has any idea please share it with me.