コード例 #1
0
ファイル: CarMover.cs プロジェクト: Der-Die-Das/LudumDare42
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            MovingCar = GetHitCar();

            //not moving cars, hehe
            if (MovingCar == null)
            {
                ParkingSlot slot = GetHitParkSlot();
                if (slot != null && slot.Unlocked == false)
                {
                    if (moneyController.Money >= ParkingSlot.UnlockPrice)
                    {
                        moneyController.Money -= ParkingSlot.UnlockPrice;
                        slot.Unlock();
                        boughtSound.Play();
                        if (SpotBought != null)
                        {
                            SpotBought();
                        }
                    }
                }
            }
        }
        else if (Input.GetMouseButton(0))
        {
            if (MovingCar != null)
            {
                Vector3 newPos = cam.ScreenToWorldPoint(Input.mousePosition);
                MovingCar.transform.position = new Vector3(newPos.x, newPos.y, 0);
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            if (MovingCar != null)
            {
                ParkingSlot slot = GetHitParkSlot();
                if (slot != null && slot.Occupied == null && slot.Unlocked)
                {
                    if (slot.CanGetAssigned(MovingCar) == false)
                    {
                        ReturnCar();
                        return;
                    }
                    SetCarToNewSlot(slot);
                    if (slot is IdleSlot && ((IdleSlot)slot).SlotType == IdleSlot.IdleSlotType.DepartSlot)
                    {
                        departureSound.Play();
                    }
                    return;
                }
                ReturnCar();
            }
        }
    }