- Home /
Question by
galaboy · Jan 04, 2014 at 06:28 AM ·
scriptingbasicsinvokerepeating
invoke repeating not working
i was trying invokeRepeating, but i couldn't get how it works.below is the script i used for learning invokeRepeating. the script is for enemy, where he has to shoot projectiles for every 1 second. need help.
using UnityEngine;
using System.Collections;
public class cube_script : MonoBehaviour {
public int speed = 5;
public GameObject cubeProjectile;
public float projectileOffset;
Vector3 position;
private float someValue = 0f;
public Rigidbody projectile;
// Update is called once per frame
void Update () {
//float amtToMove = speed * Time.fixedDeltaTime;
//transform.Translate(Vector3.forward * amtToMove);
//transform.rotation = Quaternion.Euler(new Vector3(0,0,100 * Time.time));
}
void instantiating()
{
Vector3 position = new Vector3(transform.position.x,transform.position.y,
transform.position.z + projectileOffset);
Instantiate(cubeProjectile, position, Quaternion.identity);
Debug.Log(" instantiating ");
}
void example()
{
InvokeRepeating("instantiating", 0, 1F);
}
}
Comment
Best Answer
Answer by Patel-Sagar · Jan 04, 2014 at 07:07 AM
you need to call example() from start() or other place where you want. but at least you have to call it once.
Your answer
![](https://koobas.hobune.stream/wayback/20220613125511im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how does invokerepeating work 2 Answers
What does the word for mean in javascript? 1 Answer
Why button is not display the window 2 Answers
Game is Paused Menu shows up 0 Answers
java script to c# conversion 2 Answers