Есть скрипт стрельбы:
- Код: Выделить всё
using UnityEngine;
using System.Collections;
public class shoot : MonoBehaviour {
Transform Tar_rot;
GameObject Obj;
GameObject Bullet;
int speed;
float waitTime;
float curTime;
// Use this for initialization
void Start () {
speed=1000;
waitTime=0.2f;
curTime=0;
Tar_rot = GameObject.Find("Main Camera").transform;
Obj = GameObject.Find("bullet");
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0)) {
curTime=0;
GameObject Bullet = (GameObject) Instantiate(Obj, Tar_rot.position, Tar_rot.rotation);
Bullet.rigidbody.velocity = Tar_rot.TransformDirection(0, 0, speed);
}
if (Input.GetMouseButton(0) ) {
if (curTime<waitTime) {
curTime=curTime+Time.deltaTime;
}
else {
curTime=0;
GameObject Bullet = (GameObject) Instantiate(Obj, Tar_rot.position, Tar_rot.rotation);
Bullet.rigidbody.velocity = Tar_rot.TransformDirection(0, 0, speed);
}
}
}
}
Он висит на оружии.
Есть скрипт убиения пуль:
- Код: Выделить всё
using UnityEngine;
using System.Collections;
public class collisions : MonoBehaviour {
void OnCollisionEnter(Collision Info) {
if (transform.gameObject.name!="bullet")
Destroy(transform.gameObject);
}
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
if ((transform.position.y<-100)||(transform.position.y>160)||(transform.position.x>1000)||(transform.position.x<-1000)||(transform.position.z>1000)||(transform.position.z<-1000))
if (transform.gameObject.name!="bullet")
DestroyImmediate(transform.gameObject);
}
}
Он висит на пуле. (Проверки имени нужны чтобы не уничтожать пулю-оригинал, которая всегда должна быть на сцене)
Проблема - пули чаще всего без проблем пролетают стены и не умирают, а убивает их уже проверка выхода за мир. Если сделать скорость поменьше, что это уже никакие не пули, но они благополучно убиваются.
Как исправить, т.е. сделать так, чтобы всегда работал детект вхождения в коллизию. Ибо тогда можно будет сделать удобные деколи/частицы.