- Home /
Shooting Script which don't works:
i use a script for a FPS but it don't works
using UnityEngine;
using System.Collections;
public class shooting : MonoBehaviour
{
public float bulletSpeed = 10;
public Rigidbody bullet;
void Fire()
{
Rigidbody bulletClone = (Rigidbody) Instantiate(bullet, transform.position, transform.rotation);
bulletClone.velocity = transform.forward * bulletSpeed;
}
void Update ()
{
if (Input.GetButtonDown("Fire1"))
Fire();
}
i use unity 5.1.0, Can you help me?
Answer by tormentoarmagedoom · May 10, 2018 at 09:14 AM
Good day.
When you ask for help, you need to give all information so you can recieve the best answer!
By now, you should say if you detect the if sentence in Update, I always recomend to use Keycode for inputs, to prevent mistakes. And recommend to add a Debug.Log sentences to check if the code is going as you want.
if (Input.GetButtonDown(Keycode.Mouse0))
{
Debug.Log("Trying to fire");
Fire();
}
(with Keycode you are sure you dont make a mistake in this line)
Then i dont know if is correct what you do for instantiating, i think is better do this:
void Fire()
{
GameObject bulletClone = Instantiate(bullet, transform.position, transform.rotation) as GameObject;
bulletClone.Rigidbody .velocity = transform.forward * bulletSpeed;
Debug.Log ("Bullet created");
}
Try it and tell us what!
If worked/helped, accept the answer!
Bye! :D
Your answer
Follow this Question
Related Questions
variable not being changed outside of a method. [C#] 3 Answers
Look On Cursor Problem 1 Answer
Setting a random animation frame from multiple animations 0 Answers
C# Children of GameObject has it's script disabled after SetActive(false) and SetActive(true) 1 Answer
My raycast wont function properly 0 Answers