How to make a shooting bow?
Hello! I am quite new to unity and for a couple days now I've been trying to learn Javascript and make a bow shooting script for my survival game and have tried everything I could think of and just can't get it to work the way I want it to.
This is the main script that is supposed to bind things together.
#pragma strict
var Arrow : Rigidbody;
var Speed = 50;
var Bow : Transform;
public var ShootScript : ShootArrow;
public var PlaceScript : PlaceArrow;
function Update ()
{
if(Input.GetMouseButton(0))
{
GetComponent.<Animation>().Play("DrawBow");
PlaceScript.GetComponent(PlaceArrow).Place();
}
}
function Shooting()
{
GetComponent.<Animation>().Play("ShootBow");
ShootScript.GetComponent(ShootArrow).Shoot();
}
This next script is supposed to place an arrow on the bow
#pragma strict
var Arrow : Rigidbody;
var Speed = 10;
public var MainScript : BowShooting;
var Shooting = false;
function Place()
{
var clone : Rigidbody = Instantiate(Arrow, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection(Vector3(0, 0, Speed));
clone.transform.parent = gameObject.transform;
yield WaitForSeconds(1);
Shooting = true;
}
function Update()
{
if (Input.GetMouseButtonUp(0) && Shooting == true)
{
MainScript.GetComponent(BowShooting).Shooting();
}
}
And the last one is supposed to shoot it
#pragma strict
var Arrow : Rigidbody;
var Speed = 50;
function Shoot ()
{
var clone : Rigidbody = Instantiate(Arrow, transform.position, transform.rotation);
Physics.IgnoreCollision(clone.GetComponent.<Collider>(), transform.root.GetComponent.<Collider>());
clone.velocity = transform.TransformDirection(Vector3(0, 0, Speed));
clone.transform.Rotate(90, Time.deltaTime, 90);
}
I have pretty much given up on trying to do this by myself because nothing I've tried worked and now it doesn't even shoot(It was shooting before when it was all in one script but I couldn't figure out how to animate it and place the arrow that way.) So can someone help me?
Your answer
Follow this Question
Related Questions
First person camera flipping by looking up or down too far. 1 Answer
Raycast Enemy AI shooting script 1 Answer
Is there something wrong with this shooting script 2 Answers
2D moving Script 1 Answer