- Home /
shot delay in between bullets
hello everyone i am siting on the computer for a few hours and i cant get the Solution any way i need a script that i can control how many bullets i want to shoot this is the code that i have now:
var bullet : GameObject;
var GoodSpaceShip : GameObject;
function Start()
{
}
function Update()
{
if(Input.GetMouseButton(0))
{
ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if(Physics.Raycast (ray, rayCastHit))
{
transform.position.x = rayCastHit.point.x;
transform.position.y = rayCastHit.point.y;
Instantiate(bullet, transform.position, transform.rotation);
}
}
}
please help me ASAP thank you!
Comment
Answer by fafase · Jul 03, 2013 at 07:42 AM
This has many solutions online, you need a timer. Are you sure you have not spent hours watching some youtube videos instead of trying to figure that out?
if(Input.GetMouseButton(0)){
if(timer > shotTimer)
{
ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if(Physics.Raycast (ray, rayCastHit))
{
transform.position.x = rayCastHit.point.x;
transform.position.y = rayCastHit.point.y;
Instantiate(bullet, transform.position, transform.rotation);
shotTimer = 0;
}
}else{
shotTimer += Time.deltaTime;
}
}
if(Input.GetMouseButtonUp(0)){
shotTimer = 0;
}
Your answer
Follow this Question
Related Questions
yield WaitForTime(1); question 3 Answers
delay question ?? 2 Answers
How to delay a shot. 4 Answers
shot delay in between bullets 1 Answer