randomly shoot using number generator
im still new to unity and im trying to write a code that shoots a laser prefab randomly from a ship, im using a random number generator to randomly shoot it but whenever i finished writing the code it said i had an error where it didnt expect the if statement on line 14
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class bullet : MonoBehaviour {
// Use this for initialization
void Start () {
InvokeRepeating ("shoot", 5, 2);
}
void shoot () {
int Randomnum = Random.Range (1, 4)
if(Randomnum == 1){
Instantiate( bullet * transform.position + (transform.right * 1f) * transform.Rotation );
}
// Update is called once per frame
void Update () {
transform.position += (Vector3.right * Time.deltaTime);
}
}
now something tells me im way off with practically all of this, but it would be pretty cool if i could have some code with a description on how it works, to "educate me on the matter". thank you
Your answer
Follow this Question
Related Questions
Randomly Placing Prefabs on a Grid 0 Answers
Aiming and shooting to the same point in third person 1 Answer
Particle rotation problems in Unity 2017.1.0f3 2 Answers
Prevent spawning if the gameobject has same position as a list of Vector3s using another list? 1 Answer
Find instantiated prefab by name 3 Answers