Hi guys
We just started a new project for our exam tomorrow. We are creating a Duck Hunting style game, where we are trying to get this guy to throw random pieces of fruit into the air.
We are not experienced in Unity or coding in general, so this is our pityful attempt of trying to instantiate random fruit at a location in the game.
using UnityEngine;
using System.Collections;
public class GameController : MonoBehaviour {
public GameObject pineapple;
public GameObject pear;
public GameObject strawberry;
public GameObject banana;
public GameObject berry;
public Vector3 spawnValue;
// Use this for initialization
void Start () {
var randomInt = Random.Range (1, 6);
Vector3 spawnPosition = new Vector3 ();
Quaternion spawnRotation = new Quaternion ();
if (randomInt = 1) {
Instantiate (pineapple, spawnPosition, spawnRotation);
} else if (randomInt = 2) {
Instantiate (pear, spawnPosition, spawnRotation);
} else if (randomInt = 3) {
Instantiate (strawberry, spawnPosition, spawnRotation);
} else if (randomInt = 4) {
Instantiate (banana, spawnPosition, spawnRotation);
} else (randomInt = 5); {
Instantiate (berry, spawnPosition, spawnRotation);
}
}
}
We get these errors:
We hope you can help us in any way.
We want fruit-sprites to be thrown from the dancing guy into the air, and they’re affected by gravity.
Regards