- Home /
Question by
wechat_os_Qy04hwWiqsL9Ov94DYr-DvD6Q · Jun 29, 2018 at 04:42 PM ·
instantiatefpsbulletmouseclickrespawn
FPS spawn bullet
Hi! Currently, I'm making an easy FPS game Here are codes I've written:
void Start () {
StartCoroutine (BulletRespawn());
}
// Update is called once per frame
void Update () {
}
IEnumerator BulletRespawn()
{
if(Input.GetMouseButton(0)) {
yield return new WaitForSeconds (0.1f);
Instantiate (bullet, respawnTr.position, Quaternion.identity);
}
}
And
public GameObject bullet;
public float bulletSpeed = 50.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
bullet.transform.Translate (0, -bulletSpeed * Time.deltaTime, 0);
}
And
public GameObject ChrCamera;
//public float mouseX;
//public float mouseZ;
public float chrSpeed = 10.0f;
// Use this for initialization
void Start () {
//Cursor.visible = false;
//Cursor.lockState = CursorLockMode.None;
}
// Update is called once per frame
void Update () {
//mouseX = Input.mousePosition.x;
//mouseZ = Input.mousePosition.z;
if (Input.GetKey (KeyCode.W)) {
ChrCamera.transform.Translate (0, 0, chrSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.S)) {
ChrCamera.transform.Translate (0, 0, -chrSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.A)) {
ChrCamera.transform.Translate (-chrSpeed * Time.deltaTime, 0, 0);
}
if (Input.GetKey (KeyCode.D)) {
ChrCamera.transform.Translate (chrSpeed * Time.deltaTime, 0, 0);
}
}
However, when I run the program, it crushes How shoud I change the code???
Comment
Your answer
Follow this Question
Related Questions
Bullet Spawn 3 Answers
Which is better, shooting a bullet from camera or from the gun itself? 3 Answers
rigidbody bullets dont spawn where i want them too. 1 Answer
Photon Networking Instantiating Problem 0 Answers
Top-down shooter shooting problem 1 Answer