I made this script instance but I get this error: Assets / Prefab / PrefabSpawner.cs (15,12): error CS0135: `PrefabPosL 'Conflicts with a declaration in a child block
using UnityEngine; using System.Collections;
public class PrefabSpawner : MonoBehaviour {
public GameObject Prefab;
private bool PrefabPosL = true;
private bool PrefabPosR = false;
// Use this for initialization
void Start ()
{
if(PrefabPosL = PrefabPosR)
{
Vector3 PrefabPosL = new Vector3(Random.Range(-2, 2), transform.position.y, transform.position.z);
Instantiate(Prefab, PrefabPosL, transform.rotation);
}
else
{
Vector3 PrefabPosR = new Vector3(Random.Range(2, 2), transform.position.y, transform.position.z);
Instantiate(Prefab, PrefabPosR, transform.rotation);
}
}
// Update is called once per frame
void Update ()
{
}
Answer by gjf · Jan 31, 2016 at 09:53 PM
in future, please format ALL of the code so that error messages are accurate. in your example, the error is stated as line 15, but it's actually line 10 as posted:
if(PrefabPosL = PrefabPosR)
this is not testing if they are the same - that's
if(PrefabPosL == PrefabPosR)
what you've tried to do is assign the value of PrefabPosR
to PrefabPosL
and then the if
tests whether it's true
or not...
Your answer
Follow this Question
Related Questions
*Solved* Loop instantiating objects causes my Unity Editor to crash 1 Answer
Problem when instanciating objects on keypress 0 Answers
How to know where my object is going to fall? 1 Answer
Gameobjects instantiating in the wrong position 0 Answers
How to make a cylinder that dynamically connects two objects? 0 Answers