- Home /
DrawRay with a custom class.
I have 2 simple scripts witch have to dray a ray from an objects position upwards but it dosent do anything,
--the class witch draws the ray
#pragma strict
class aClass
{
var pos : Transform;
function Update()
{
if(pos != null)
{
Debug.DrawRay(pos.position,Vector3(0,10,0), Color.red);
}
}
}
--the script witch sets the transform
#pragma strict
var grid : aClass = new aClass();
function Start ()
{
grid.pos = gameObject.transform;
}
The scripts are rather simple but it dosent work and it dosent have any warnongs or errors.What am I doing wrong?
aClass need to be extended by $$anonymous$$onoBehaviour to use Update function
Well then I have no idea what could possibly work ..... those scripts are just a few of what I have tried and I dont know what to do and I am stuck here....I know I'm missing something......could somebody give me a code snippet and an explanation....or just an explanation?
Answer by spectre1989 · Aug 11, 2013 at 11:58 AM
Where is grid.Update() called? It looks like aClass isn't a MonoBehaviour so Unity will not automatically call it's Update() function. So unless your second script which sets the transform is also calling grid.Update() in it's own Update() function, then Debug.DrawRay is never getting called.
Don't forget to flag this as the correct answer if it worked for you =)
I have another question....why if the aGrid class extends $$anonymous$$onoBehaviour assigning a transform from the second script gives me a NullReferenceException.....I know I am not allowed to use the "new" keyword if it extends $$anonymous$$onoBehaviour.
Your answer
![](https://koobas.hobune.stream/wayback/20220613111927im_/https://answers.unity.com/themes/thub/images/avi.jpg)