- Home /
Question by
jjesh · Dec 04, 2014 at 11:45 AM ·
movementshootingmoveinvokerepeating
I can't get InvokeRepeating to work in my script
I have a pretty simple script, where a turret moves up, fires, waits, and then moves back down. The problem is that I want it to repeat, but when I try using InvokeRepeating nothing happens. I've looked at the documentation and can't see anything wrong with what I wrote. Any ideas?
#pragma strict
var bulletPrefab : Transform;
function Start()
{
InvokeRepeating("Shoot",0,6);
}
function Shoot()
{
MoveOverTime( transform, Vector3( 0, 3, 0 ), 0.5 );
yield WaitForSeconds(0.8);
var bullet = Instantiate(bulletPrefab, transform.Find("e_Spawnpoint1").transform.position,
Quaternion.identity);
bullet.gameObject.tag = "enemyProjectile";
bullet.rigidbody.AddForce(transform.forward * 1500);
var bullet2 = Instantiate(bulletPrefab, transform.Find("e_Spawnpoint2").transform.position,
Quaternion.identity);
bullet2.gameObject.tag = "enemyProjectile";
bullet2.rigidbody.AddForce(-transform.forward * 1500);
yield WaitForSeconds(2.0);
MoveOverTime( transform, Vector3( 0, -3, 0 ), 0.5 );
}
function MoveOverTime( theTransform : Transform, d : Vector3, t : float )
{
var rate : float = 1.0/t;
var index : float = 0.0;
var startPosition : Vector3 = theTransform.position;
var endPosition : Vector3 = startPosition + d;
while( index < 1.0 )
{
theTransform.position = Vector3.Lerp( startPosition, endPosition, index );
index += rate * Time.deltaTime;
yield;
}
theTransform.position = endPosition;
}
Comment
Best Answer
Answer by jenci1990 · Dec 04, 2014 at 11:49 AM
function Start() {
InvokeRepeating("Repeat",0f,6f);
}
function Repeat() {
StartCoroutine("Shoot");
}
Your answer
Follow this Question
Related Questions
Objects move on play 3 Answers
How to make an object without Rigidbody move at the same speed as an object with Rigidbody? 1 Answer
How do I translate my ship left and right and have it rotate at the same time? 1 Answer
Using Input.GetAxis on a 2 Player Game 2 Answers
How do I make a 3D character move and rotate (turn) the same direction they move? c# 0 Answers