I get this error even though i’ve assigned variables (v1 and v2). This is driving me insane. Any help is appreciated.
using UnityEngine;
using System.Collections;
public class BulletController : MonoBehaviour {
public float speed;
public PlayerController player;
public BulletController largeBullet;
private float spawnChooser;
public Transform firePoint;
public GameObject targetBullet;
public float v1;
public float v2;
// Use this for initialization
void Start () {
player = FindObjectOfType<PlayerController> ();
largeBullet = FindObjectOfType<BulletController> ();
if (player.transform.localScale.x < 0) {
speed = -speed;
transform.localScale = new Vector3 (-1f, 1f, 1f);
} else if (player.transform.localScale.x > 0)
transform.localScale = new Vector3 (1f, 1f, 1f);
}
// Update is called once per frame
void Update () {
rigidbody2D.velocity = new Vector2 (speed, rigidbody2D.velocity.y);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Enemy") {
Destroy (gameObject);
}
}
public void BulletTermination()
{
Destroy (this.gameObject);
}
public void SpawnChooser()
{
spawnChooser = Random.value;
if (spawnChooser < 0.2)
{
Instantiate (largeBullet, firePoint.position, firePoint.rotation );
targetBullet = gameObject;
rigidbody2D.velocity = new Vector2(speed, rigidbody2D.velocity.y = v1 ); //error here
}
if (spawnChooser < 0.4 && spawnChooser > 0.2)
{
Instantiate (largeBullet, firePoint.position, firePoint.rotation );
targetBullet = gameObject;
rigidbody2D.velocity = new Vector2(speed,rigidbody2D.velocity.y = v2); //error here
}
if (spawnChooser < 0.6 && spawnChooser > 0.4) {
Instantiate (largeBullet, firePoint.position, firePoint.rotation);
targetBullet = gameObject;
rigidbody2D.velocity = new Vector2(speed, rigidbody2D.velocity.y = -v2); //error here
}
if (spawnChooser < 0.8 && spawnChooser > 0.6)
{
Instantiate (largeBullet, firePoint.position, firePoint.rotation );
targetBullet = gameObject;
rigidbody2D.velocity = new Vector2(speed,rigidbody2D.velocity.y);
}
if (spawnChooser < 1 && spawnChooser > 0.8)
{
Instantiate (largeBullet, firePoint.position, firePoint.rotation );
targetBullet = gameObject;
rigidbody2D.velocity = new Vector2(speed,rigidbody2D.velocity.y = -v1); //error here
}
}
}