A little help working out some Odd Errors (UnityEngine Errors)

alt text

Hi everyone i'm having some odd errors that started appearing when writing this script, i'm normally ok at debugging but im at an end with this one and wonder if some extra eyes could help me understand what the problem is.

using UnityEngine; using System.Collections;

public class RayTest : MonoBehaviour { #region Main Fields

public float rayLength = 25.0f;

public float playerMoveSpeed = 150;

//public Transform placeHolder; 

//Creates a ray object named aimRay
private Ray aimRay;
private Ray aimRayBounce;

//Creates RaycastHits to store information from objects colliding with the ray
static RaycastHit rayHit01; 

// For the gameobject and hit transform
private Transform playerTrans;
Transform reflectedTrans;

//Raybounce Vector
private Vector3 rayBounceVector = rayHit01.transform.position;


#region aimLine Fields

static LineRenderer aimLine;        


void Awake ()
    //Get this transform (might not need)
    playerTrans = this.GetComponent<Transform>();


void Start ()
    //aimLine (the drawn line) Initialisation
    aimLine = gameObject.AddComponent<LineRenderer>();
    aimLine.SetWidth(0.14f, 0.14f);
    aimLine.SetColors(Color.red, Color.red);
    aimLine.useWorldSpace = true;


void Update ()
    #region PlayerMovement
    //Player Rotation Method Call (TEMP)

    //cast Debug.DrawRay for checking ray length
    Debug.DrawRay(transform.position, transform.up * rayLength);


    //Raycast Code      
    aimRay = new Ray(playerTrans.position,transform.forward);
    if(Physics.Raycast(aimRay.origin,transform.up, out rayHit01, rayLength))

        Debug.Log("You hit a collider");
        Debug.Log("Name: " + rayHit01.collider.name + 
                  " - Position: "+ rayBounceVector + 
                  " - Distance: " + rayHit01.distance +
                  " - Normals: " + rayHit01.normal);

        aimLine.enabled = true;

        Debug.DrawRay(rayHit01.point, Vector3.Reflect(rayHit01.point, rayHit01.normal));

        //The ray is not colliding with anything
        Debug.Log("Not colliding");

        aimLine.enabled = false;
    aimLine.SetPosition(0, transform.position);
    aimLine.SetPosition(1, rayHit01.point);

    //TEMP: sets the final position to be the placeholder when finnished there should be an if
    //statement which askes if a colliders been hit, set to rayhitpoint else set to the end of the
    //rays length with ... ray.getpoint
    //aimLine.SetPosition(2, placeHolder.position);


// Rotate: Player move script (TEMP)
void PlayerRotate ()
    float amtToMove = Input.GetAxis("Horizontal") * playerMoveSpeed * Time.deltaTime;

It's probably this line:

private Vector3 rayBounceVector = rayHit01.transform.position;

This code would be called during the constructor, but rayHit01 (or its transform) is not yet set up. For this reason I believe one should do such assignments in the Awake or Start function.