[英]Gun bullet shoots wrong direction and shoots 2 bullet
我是 Unity3D 引擎的新手。 我正在创建由非 Ray Casting 制成的小型枪械游戏。 当我开枪时,子弹向上移动,一次射出 2 发子弹(一次单击) 。
我不知道是怎么回事!
这是视频文件:
https://drive.google.com/file/d/1SeT9eLcly9Wv551mSy4bnEpgI8E1FL5l/view?usp=sharing
这是代码:
射击子弹.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShootingBullet : MonoBehaviour
{
// Start is called before the first frame update
public Transform spawnPoint;
public GameObject bullet;
public float speed = 5f;
void Start()
{
}
// Update is called once per frame
void Update()
{
//Debug.Log("working");
if (Input.GetButtonDown("Fire1")) //
{
ShootBullet();
}
}
private void ShootBullet()
{
GameObject cB = Instantiate(bullet, spawnPoint.position, bullet.transform.rotation);
Rigidbody rig = cB.GetComponent<Rigidbody>();
rig.AddForce(spawnPoint.forward * speed, ForceMode.Impulse);
}
}
BulletScript.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletScript : MonoBehaviour
{
private void OnCollisionEnter(Collision collision)
{
// Destroy(gameObject);
//Debug.Log("working");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.