Ejemplo n.º 1
0
        // Update is called once per frame
        void Update()
        {
            if (CanCreate && Input.GetMouseButtonDown(0) && Bear.CheckCanBuyPenguin())
            {
                var ts = Input.mousePosition;

                ts.x = Mathf.Clamp(ts.x, 0.0f, Screen.width);
                ts.y = Mathf.Clamp(ts.y, 0.0f, Screen.height);

                var tpr = Camera.main.ScreenPointToRay(ts);

                var hit = new RaycastHit();
                if (Physics.Raycast(tpr, out hit))
                {
                    if (hit.collider.gameObject.tag == "Ground")
                    {
                        var p = hit.point;
                        p.y += offset_height;

                        var pen = Manager.CreatePenguins(p);
                        if (!pen)
                        {
                            return;
                        }
                        var type = Bear.BuyPenguin();
                        switch (type)
                        {
                        case PenguinManager.PenguinType.Json:
                            pen.gameObject.AddComponent <JsonBehavior>();
                            break;

                        case PenguinManager.PenguinType.Gun:
                            pen.gameObject.AddComponent <GunBehavior>();
                            break;

                        case PenguinManager.PenguinType.Gold:
                            pen.gameObject.AddComponent <TakeGoldBehavior>();
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }