There is a spawnPoint in front of character. And, I created a Prefabs “Bullet” which has rigidbody.
In the character controller script,
private var character : CharacterController;
var bulletPrefabs : Transform; //I drag Bullet to it in inspector
private var canShot = true;
function Update()
{
if ( character.isGrounded )
{
if ( !shotJoystick.IsFingerDown() )
canShot = true;
if ( canShot shotJoystick.tapCount == 1 )
{
var bullet : GameObject = Instantiate(bulletPrefabs, GameObject.FindGameObjectsWithTag("spawnPoint").transform.position, Quaternion.identity) as GameObject;
bullet.rigidbody.AddForce(transform.forward * 2000);
canShot = false;
}
}
Errors:
- ‘transform’ is not a member of ‘(UnityEngine.GameObject)’.
- NullReferenceException: Object reference not set to an instance of an object
When I play the game, I just one tap, over 10 bullets fire, but not just one tap one bullet.
And, the direction of firing is according to the left joystick’s direction, but not towards the top of the screen.
How should I fix it?