NullReferenceException UnityEngine.Camera.WorldToScreenPoint (Vector3 position)

here is my script,the ploblem is:

NullReferenceException UnityEngine.Camera.WorldToScreenPoint (Vector3 position)

#pragma strict

var npcHeight:float;

var hero:  GameObject;

private var  name :String= "我是";

private var myCamera:Camera;

public var  blood_red:Texture2D;

public  var  blood_black:Texture2D;

private var  HP :int=100;

function Start ()



        hero = GameObject.FindGameObjectWithTag("test");



 var size_y:float;


size_y = collider.bounds.size.y;

 var scal_y:float ;      

 scal_y = transform.localScale.y;


        npcHeight = (size_y *scal_y) ;




var x:int;

function OnCollisionStay(myCollision : Collision) {



function Update(){


function OnGUI (){

var worldPosition:Vector3 = new Vector3 (transform.position.x , transform.position.y + npcHeight,transform.position.z);


        var position : Vector2=myCamera.WorldToScreenPoint (worldPosition);


        position = new Vector2 (position.x, Screen.height - position.y);



         var bloodSize :Vector2= (new GUIContent(blood_red));


var blood_width:int;
blood_width = blood_red.width * HP/100;


        GUI.DrawTexture(new Rect(position.x - (bloodSize.x/2),position.y - bloodSize.y ,bloodSize.x,bloodSize.y),blood_black);


        GUI.DrawTexture(new Rect(position.x - (bloodSize.x/2),position.y - bloodSize.y ,blood_width,bloodSize.y),blood_red);


You have not set myCamera anywhere in this code - is it complete? If not, set it like below at Start (or at Update, if the current main camera may change during the game):

myCamera = Camera.main;