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)
thanzx i fixed it but now my question is how can i make my fireball move
– mangohackThe 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
– aldonaletto