I have a charge shot for my player character in which it instantiates a prefab with a script containing
var appliedDamage : float;
and a couple of other functions which don't effect the variable at all!
In the firing script for my player I have this function:-
if (Input.GetButton("ChargeFire"))
{
StopFunction = true;
particleEmitter.emit = false;
if (CanCharge == true)
{
Ammo = Ammo - 30*Time.deltaTime;
ChargeSize = ChargeSize + 1*Time.deltaTime;
CSamount = CSamount + 25*Time.deltaTime;
}
if (Ammo <=1)
{
Hold();
CSamount = 90;
}
}
if (Input.GetButtonUp("ChargeFire"))
{
//SetDamageAmount();
ChargeShot();
if (Ammo <=2)
{
StopFunction = false;
Reloading();
}
else
{
StopFunction = false;
}
}
function ChargeShot()
{
var chargedshot = Instantiate(ChargeTea, transform.position, transform.rotation);
chargedshot.rigidbody.velocity = transform.forward*5 + transform.up*5;
chargedshot.transform.localScale = Vector3 (ChargeSize/20,ChargeSize/20,ChargeSize/20);
yield WaitForSeconds (0.1);
var senddamage = ChargeTea.GetComponent (ChargeShotScript);
senddamage.appliedDamage = CSamount;
ChargeSize = 0;
CanCharge = true;
yield WaitForSeconds (0.2);
CSamount = 0;
}
I have all the variable set just havn't incldued them to save space. My problem is that in the ChargeShot function, where it sends the damage accumulated during Input.GetButtonDown, my 1st shot doesn't set any damage. Every shot after that sets the damage amount on the prefab clone to that of the previous shot. Obviously I don't want it to do this (hence why it's a problem lol), but I may be scripting it wrong.
Could anybody please shed some light on what I may be doing wrong?
edit Sorry I commpletely forgot to include the input.GetButtonUp part of my code which is how I call the ChargeShot function. Cheers for your patience.
How are you calling your ChargShot function?
– tool55Not 100%. I see you've added a similar answer without it. So I guess not?
– boofereiApparently the following line is not necessary (line 7 in my original answer above):
– boofereientry.callback = new EventTrigger.TriggerEvent();