Hi im having trouble using Physics.Raycast to run functions on a game object it seems somewhat simple but i cant for the life of me see what im missing. If anyone could look over this bit of code for me and give me a hint for what im missing i would be very much in there debt
GUIScript
public bool _Scanning = false;
public Ray ray;
public RaycastHit hit;
// Update is called once per frame
void Update () {
if (_Scanning == true){
if(Input.GetButton("Fire1")) {
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Scan();
}
}
}
private string type;
private int surfTemp;
private float mass;
private float radius;
void Scan(){
if (Physics.Raycast(ray, out hit, 20)){
Debug.DrawLine(ray.origin, hit.point);
if (hit.transform.gameObject.GetComponent<StarTypeA>()){
type = StarTypeA.GetStarType();
surfTemp = StarTypeA.GetStarTemp();
mass = StarTypeA.GetStarMass();
radius = StarTypeA.GetStarRadius();
_Scanning = false;
Menu ("showScan");
}
}
}
Stars Script (that StarTypeA inherits from)
string type;
int surfTemp;
float mass;
float radius;
string desc;
public int planetCount;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public string GetStarType (){
return type;
}
public int GetStarTemp(){
return surfTemp;
}
public float GetStarMass(){
return mass;
}
public float GetStarRadius(){
return radius;
}
public int GetPlanetCount(){
return planetCount;
}
At the moment the error im getting is:
‘error CS0120: An object reference is required to access non-static member’
But i was under the impression that i had an object reference from the raycast but now i just dont know. so im guessing that i have missed something somewhere.
again any help would be very much appreciated
many many thanks Chronos-L i was starting to feel like i was just running in to a wall. i cant grant karma yet but when i can i will
– FarKing