Lacking some basic Unity C# knowledge, please help.
How do I access a script class on another object?
How do I include another class in C# with using?
I have a chicken game object that has this C# script on it.
using UnityEngine;
using System.Collections;
public class ChickenBehaviour : MonoBehaviour {
public float speed = 8f;
}
In another object, how can I get the ChickenBehaviour class and see it’s members?
using UnityEngine;
// ??????? how should the using be done ???????
using ChickenBehaviour; // this fails
public class PlayerController : MonoBehaviour
{
void Update () {
if (Input.GetButtonDown("Fire1")) {
Ray theRay = playerCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool mouseHitSomething = false;
if (Physics.Raycast (theRay, out hit)) {
// ??????? how should the class be accessed ???????
// don't know if this fails, can't get past using
ChickenBehaviour behave = hit.transform.gameObject.GetComponent(ChickenBehaviour);
Debug.Log("clicked on chicken with speed " + behave.speed);
}
}
}