C# 子弹变成了弹孔
在我的项目中,我有枪。我的子弹使用刚体,当我开火时会在枪管处产生。我的子弹穿过墙壁,有时穿过墙壁 我知道,在物理学中,光线投射非常简单:C# 子弹变成了弹孔,c#,unity3d,C#,Unity3d,在我的项目中,我有枪。我的子弹使用刚体,当我开火时会在枪管处产生。我的子弹穿过墙壁,有时穿过墙壁 我知道,在物理学中,光线投射非常简单: public GameObject par; public int damage; void Update() { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
public GameObject par;
public int damage;
void Update()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast(ray, out hit, 100))
{
GameObject particleClone = Instantiate(par, hit.point, Quaternion.LookRotation(hit.normal)) as GameObject;
Destroy(particleClone, 2);
hit.transform.SendMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
}
}
}
在刚体中我该怎么做?
子弹将成为粒子系统或弹孔图像
我应该使用OnCollisionCenter()
还是OnTriggerCenter()
如何使其成为弹孔图像或粒子系统?可以同时使用OnCollisionCenter和OnTriggerCenter;但是,请看一下关于差异的解释:我在以下内容中找到了此JavaScript: 你拿着这个,把它加到你武器的发射器上:
我的名字说明了一切,你能把它翻译成c吗?C
var bulletTex : GameObject[]; // creates an array to use random textures of bullet holes
function Update ()
{
var fwd = transform.TransformDirection(Vector3.forward); //casts our raycast in the forward direction
var hit : RaycastHit;
Debug.DrawRay(transform.position, fwd * 10, Color.green); //drays our raycast and gives it a green color and a length of 10 meters
if(Input.GetButtonDown ("Fire1") && Physics.Raycast(transform.position, fwd, hit, 10))
{ //when we left click and our raycast hits something
Instantiate(bulletTex[Random.Range(0,3)], hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)); //then we'll instantiate a random bullet hole texture from our array and apply it where we click and adjust
// the position and rotation of textures to match the object being hit
}
}