子弹贴花侧身

时间:2014-05-12 13:01:30

标签: unity3d unityscript raycasting

当我将一个子弹贴花纹理实例化到一个光线投射的生命点时,由于某种原因它没有被证明是任何帮助,因为它适用于它们。

贴花的纹理在一个平面上,它平放在地面上方(光线投射的高度。)

这是光线投射拍摄代码:

var TheDammage = 100;
var BulletHole : Transform;
var canShoot : boolean;
var NoShootZoneTrigger : Transform;
//var AmmoText : GUIText;
var Ammo : float;
var MaxDistanceInMetersMax35 = 25;
var GunFirePistol : AudioClip;
var DryGunFirePistol : AudioClip;

function Start() {
    canShoot=true;
}
function Update () {
    if (MaxDistanceInMetersMax35>25){
        MaxDistanceInMetersMax35 = 35;
    }
    var hit : RaycastHit;
    var ray : Ray = 
    Camera.main.ScreenPointToRay (Vector3(Screen.width*0.5, Screen.height*0.5,0));
    //AmmoText.text = "Bullets Remaining: "+Ammo;

    if (Input.GetMouseButtonDown(0)&& canShoot==true){
        if (Physics.Raycast(ray, hit, 100)){
            if (Ammo >0){
                Ammo--;
                audio.PlayOneShot(GunFirePistol);
            }
            {
                Debug.Log(hit.distance);
                if (hit.distance<MaxDistanceInMetersMax35){
                    var particleClone = Instantiate(Effect, hit.point,
                    Quaternion.LookRotation(hit.normal));
                    Destroy(particleClone.gameObject, 15);
                    hit.transform.SendMessage("ApplyDammage",
                    TheDammage, SendMessageOptions.DontRequireReceiver);
                }
            }
            if (Input.GetMouseButtonDown(0)&& canShoot==false){
                Debug.Log("No Shooting Zone!");
            }
        }
        if (Input.GetKeyDown("w")){
            canShoot = false;
        }
        if (Input.GetKeyUp("w")){
            //animation.Play("GunWalkDone");
            canShoot=true;
        }
    }
    if (Ammo<1){
        canShoot=false;
        if (Input.GetMouseButtonDown(0)&& canShoot==false){
            //AmmoText.text="";
            audio.PlayOneShot(DryGunFirePistol);
        }
    }
    if (Ammo<18) {
        if (Input.GetKeyDown("r")){
            animation.Play("Reload");
        }
    }
}

0 个答案:

没有答案