Scripting error (28996)

hi everyone i trying to my character shoot fireball but i got htis error

NullReferenceException: Object reference not set to an instance of an object
this is my script

var speed : float = 3.0;
var rotateSpeed : float = 3.0;
var bullitPrefab: Transform;

function Update () {
  var controller : CharacterController = GetComponent(CharacterController);

  // Rotate around y - axis
  transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);

  // Move forward / backward
  var forward : Vector3 = transform.TransformDirection(Vector3.forward);
  var curSpeed : float = speed * Input.GetAxis ("Vertical");
  controller.SimpleMove(forward * curSpeed);

  if(Input.GetButtonDown("Jump"))
  {
    var bullit = Instantiate(bullitPrefab, GameObject.Find("SpawnPoint").Transfrom.position,Quaternion.identity);

  } 
}
@script RequireComponent(CharacterController)

1 Answer

1

There’s a problem in this instruction:

Instantiate(bullitPrefab,GameObject.Find("SpawnPoint").Transfrom.position,...

There’s no Transfrom component - it’s .transform.position:

Instantiate(bullitPrefab,GameObject.Find("SpawnPoint").transform.position,...

Notice that transform must be in lower case, since it’s a game object variable.
Additionally, make sure that an empty object named “SpawnPoint” exists (that’s where the bullets will be instantiated).

thanzx i fixed it but now my question is how can i make my fireball move

The best way is to set the rigidbody velocity. You can use the transform.forward vector, what will shoot the bullet horizontally in the direction the player is turned to: // shoot the bullet at 10m/s bullit.rigidbody.velocity = transform.forward * 10; A better alternative is to use the camera forward direction, so you can control the elevation angle you're shooting - substitute transform.forward by Camera.main.transform.forward