Hi all, I read lots of similar question on unity community but I can’t resolve my problem. I have 2 scripts. LeftShoulder.cs that has a method: prova(). From MainGUI.cs I want call the method prova(). But Unity return me this error: object reference not set to an instance of an object .
This is my code.
using UnityEngine;
using System.Collections;
public class LeftShoulder : MonoBehaviour {
public Transform from;
public Transform to;
public float speed = 100.0F;
public Component[] allcomponent;
// Use this for initialization
void Start () {
allcomponent=gameObject.GetComponents(typeof(Component));
// for(int i=0;i<allcomponent.Length;i++){
// Debug.Log(allcomponent*);*
// }
-
}*
-
// Update is called once per frame*
-
void Update () {*
// transform.Rotate (1f, 0f, 0f);
// ruota ();
// transform.rotation = Quaternion.Slerp(from.rotation, to.rotation, Time.time * speed);
- }*
- public void ruota(int control){*
-
if (control==1) {*
_ transform.Rotate (Vector3.right * Time.deltaTime * 10);_
-
}*
-
}*
}
and MainGUI.cs
using UnityEngine;
using System.Collections;
public class MainGUI : MonoBehaviour {
-
public Component spallasx;*
-
public LeftShoulder spalla;*
-
// Use this for initialization*
-
void Start () {*
-
}*
-
// Update is called once per frame*
-
void Update () {*
-
}*
-
void OnGUI () {*
-
GUI.BeginGroup(new Rect(0,0,120,120));*
-
GUI.Box (new Rect (0,0,120,120), "Menu");*
-
int a = 0;*
-
if (GUI.Button (new Rect (10, 20, 100, 30), "primo bottone")) {*
// spallasx = gameObject.GetComponent(“LeftShoulder”);
// Debug.Log(“a”);
-
a = 1;*
-
spalla.ruota(a);*
-
}*
-
GUI.EndGroup ();*
-
}*
}