This question was
closed Nov 27, 2015 at 06:57 PM by
Ashia40 for the following reason:
Resolved
Question by
Ashia40 · Nov 27, 2015 at 04:50 PM ·
c#gameobjectinstantiatescript error
instantiate a gameobject since another script
Hello people, I have a small problem.
In fact I would want to instantiate a gameobject since another script.
Here is the error that I reçoi:NullReferenceException: Object references not set to the year authority of the object year GenDongeon.geng () (at Assets Assets/Scripts/GenDongeon.cs:30 Scripts) GenDongeon+pause > c __ Iterator0. MoveNext () (at Assets Assets/Scripts/GenDongeon.cs:21 Scripts)
Thank you.
Sorry for my bad English, because I am French.
Script Salles :
using UnityEngine;
using System.Collections;
public class Salles : MonoBehaviour {
public GameObject [] salleg1;
public GameObject [] salled1;
public GameObject [] salleu1;
public GameObject [] salleb1;
public static GameObject [] salleg;
public static GameObject [] salled;
public static GameObject [] salleu;
public static GameObject [] salleb;
public static int salg;
public static int sald;
public static int salu;
public static int salb;
void start(){
salleg = new GameObject[salleg1.Length];
salled = new GameObject[salled1.Length];
salleu = new GameObject[salleu1.Length];
salleb = new GameObject[salleb1.Length];
salg = salleg1.Length;
sald = salled1.Length;
salu = salleu1.Length;
salb = salleb1.Length;
for(int a=0;a<salleg1.Length;a++){
salleg[a] = salleg1[a];
}
for(int b=0;b<salled1.Length;b++){
salled[b] = salled1[b];
}
for(int c=0;c<salleu1.Length;c++){
salleu[c] = salleu1[c];
}
for(int d=0;d<salleb1.Length;d++){
salleb[d] = salleb1[d];
}
}
}
Script GenDongeon :
using UnityEngine;
using System.Collections;
public class GenDongeon : MonoBehaviour {
public bool g;
public bool d;
public bool u;
public bool b;
public int timep;
void Start () {
StartCoroutine (pause());
}
public IEnumerator pause(){
yield return new WaitForSeconds(timep);
geng();
gend();
genu();
genb();
}
void geng(){
if(g==true){
int rand = Random.Range (0,Salles.sald);
Instantiate (Salles.salled[rand],new Vector3(this.transform.position.x-8,this.transform.position.y,0),Quaternion.identity);
}
}
void gend(){
if(d==true){
int rand = Random.Range (0,Salles.salg);
Instantiate (Salles.salleg[rand],new Vector3(this.transform.position.x+8,this.transform.position.y,0),Quaternion.identity);
}
}
void genu(){
if(u==true){
int rand = Random.Range (0,Salles.salb);
Instantiate (Salles.salleb[rand],new Vector3(this.transform.position.x,this.transform.position.y+8,0),Quaternion.identity);
}
}
void genb(){
if(b==true){
int rand = Random.Range (0,Salles.salu);
Instantiate (Salles.salleu[rand],new Vector3(this.transform.position.x,this.transform.position.y-8,0),Quaternion.identity);
}
}
}
Comment
Best Answer
Answer by pekalicious · Nov 27, 2015 at 05:58 PM
In Salles, "start" method should be "Start". Case matters.
Answer by Ashia40 · Nov 27, 2015 at 06:56 PM
Thank you.
No problem. Please accept my answer as correct. Thanks.