Hi,
I have made a catapult where I want to launch some stones from. The catapult is animated so when I press ‘space’ my fire animation is loaded, and when this happens I would like to adress my ‘FiringScript’ attached to an empty gameObject where I want to spawn my stones.
Previosly I have been able to link to different functions in different scripts, but now I cant make it work.
My script on the catapult is:
function Update () {
if (Input.GetKeyDown (“space”))
{
animation.Play(“Fire”);
print(“FIRE!”);
AmmoRockConstructor = true;
print(“AmmoRockConstructor is true”);
FiringScript.fire(); ← I also tried accessing it with this line
}
My script on the empty gameobject:
var AmmoRockConstructor = false;
var fireSound : AudioClip;
var AmmoRock : Rigidbody;
var fireForce : float;
function fire()
{
if(AmmoRockConstructor==true)
{
audio.PlayOneShot(fireSound);
var AmmoRock : Rigidbody = Instantiate(AmmoRock, transform.position, transform.rotation);
AmmoRock.rigidbody.velocity = transform.TransformDirection(Vector3(0,0, fireForce));
//Physics.IgnoreCollision(transform.root.collider, AmmoRock.collider, true);
AmmoRock.name = “AmmoRock”;
print(“FIRED!!!”);
}
}
@script RequireComponent(AudioSource)
I did manage to spawn the stones and play the animation, but not at the same time and linked.
I have attached a screenshot.
Hope anyone has the golden point ![]()
-Take care
