Beispiel #1
0
    private void OnBulletHit(JsonData json)
    {
        int   bullet_id = GetJsonInt(json, "bullet_id");
        int   body_id   = GetJsonInt(json, "body_id");
        float x         = GetJsonFloat(json, "x");
        float y         = GetJsonFloat(json, "y");

        Instantiate(explosion_prefab, new Vector3(x, 0.5f, y), Quaternion.identity);
        if (bullet_id_to_ctrl.ContainsKey(bullet_id))
        {
            ShipShellCtrl shipShellCtrl = bullet_id_to_ctrl[bullet_id];
            Destroy(shipShellCtrl.gameObject);
        }
        Debug.Log(string.Format("bullet hit {0}, {1}, {2}, {3}", bullet_id, body_id, x, y));
    }
Beispiel #2
0
    private void OnFireBullet(JsonData json)
    {
        int           bullet_id = GetJsonInt(json, "id");
        float         x         = GetJsonFloat(json, "x");
        float         y         = GetJsonFloat(json, "y");
        float         vx        = GetJsonFloat(json, "vx");
        float         vy        = GetJsonFloat(json, "vy");
        float         speed     = GetJsonFloat(json, "speed");
        float         radius    = GetJsonFloat(json, "radius");
        ShipShellCtrl shell
            = Instantiate(shell_prefab).GetComponent <ShipShellCtrl>();

        shell.Init(x, y, vx, vy, speed, radius);
        bullet_id_to_ctrl.Add(bullet_id, shell);

        AudioSource audioSource = GetComponent <AudioSource>();

        audioSource.Play();

        Debug.Log(string.Format("create bullet {0} {1} {2} {3} {4} {5}",
                                x, y, vx, vy, speed, radius));
    }