如何将得分转换为弹药数量?

时间:2018-04-06 04:07:31

标签: unity3d unityscript

我正在制作一个游戏,如果你收集一条鱼,你就会获得一分。我想要的是,你获得的这一点也相当于玩家必须用多少弹药将这些鱼射向一只悬浮在空中的鸟。

我能以任何方式写这个或一个例子吗?我是否添加公共文本并将乐谱文本拖到那里并从那里开始。我也希望每次投篮都能得分为-1。提前谢谢我,我是C#的新手!

public class Projectileshooter : MonoBehaviour 
{

    GameObject Bullet;

    // Use this for initialization
    void Start () 
    {
        Bullet = Resources.Load ("projectile") as GameObject;
    }

    // Update is called once per frame
    void Update () 
    {
        if (Input.GetKeyDown("f"))
        {
            GameObject projectile = Instantiate (Bullet) as GameObject;
            projectile.transform.position = transform.position + Camera.main.transform.forward * 2;
            Rigidbody rb = projectile.GetComponent<Rigidbody> ();
            rb.velocity = Camera.main.transform.forward * 40;
        }
    }
}

1 个答案:

答案 0 :(得分:1)

您可以将以下脚本附加到持久性GameObject。

Start()

ShotFired()开始,获取CatchFish()中的组件,并在每次开枪时拨打public class Projectileshooter : MonoBehaviour { GameObject Bullet; public GameObject persistentGameObject; // bind this object to the one that has the AmmmoManager script in the inspector public AmmoManager ammoManager; // Use this for initialization void Start () { Bullet = Resources.Load ("projectile") as GameObject; ammoManager = persistentGameObject.GetComponent<AmmoManager>(); } // Update is called once per frame void Update () { if (Input.GetKeyDown ("f")) { GameObject projectile = Instantiate (Bullet) as GameObject; projectile.transform.position = transform.position + Camera.main.transform.forward * 2; Rigidbody rb = projectile.GetComponent<Rigidbody> (); rb.velocity = Camera.main.transform.forward * 40; ammoManager.ShotFired(1); // deduct one ammo here } } } 。对const payload = {'ActionMethod': 'CheckLogin', 'StaffCode': '15989', 'Password': 'a$a#' } var v= this.http.post("http://localhost:57863/api/Audit/",payload)` 执行相同的操作。

{{1}}

如果你想了解一些基础知识,我写了一篇简短的Introduction to Unity3D