コード例 #1
0
    private void Update()
    {
        if (Input.GetButtonDown("Toggle Bait") && !bobberIsCast)//B key
        {
            selectedBait = (selectedBait + 1) % amountOfBaitTypes;
            Debug.Log("Bait " + (selectedBait) + " selected");
            player.stats.baitInventory.changeRedText(selectedBait);
        }
        else if (Input.GetAxis("Mouse ScrollWheel") != 0.0f && !bobberIsCast)
        {
            selectedBait = ((selectedBait - (int)(10 * Input.GetAxis("Mouse ScrollWheel"))) % amountOfBaitTypes);
            if (selectedBait < 0)
            {
                selectedBait += amountOfBaitTypes;
            }
            Debug.Log("Bait " + (selectedBait) + " selected");
            player.stats.baitInventory.changeRedText(selectedBait);
        }

        if (GetComponent <debugging>().debug&& Input.GetKeyDown(KeyCode.Alpha1))//1 button
        {
            //player.stats.baitInventory.addBait(selectedBait); //just for testing bait
            player.stats.baitInventory.addBait(0);
            player.stats.baitInventory.addBait(1);
            player.stats.baitInventory.addBait(2);
            player.stats.baitInventory.addBait(3);
        }

        if (Input.GetButtonDown("Cast Fishing Pole"))//F key
        {
            if (!gameActive)
            {
                if (bobber)
                {
                    audioSrc.clip = reelSound;
                    audioSrc.loop = true;
                    audioSrc.Play();
                    bobber.Reel();
                }
                else
                {
                    if (player.stats.baitInventory.getBaitArray()[selectedBait] > 0)
                    {
                        audioSrc.clip = castSound;
                        audioSrc.Play();
                        bobber       = Bobber.Create(bobberPrefab, this, cam.GetMousePosition(), selectedBait);
                        bobberIsCast = true;

                        PlayerPrefs.SetInt("FishingBait", PlayerPrefs.GetInt("FishingBait") + 1);
                    }
                    else
                    {
                        Debug.Log("None of selected bait " + (selectedBait + 1).ToString() + " left");
                    }
                }
            }
        }
    }
コード例 #2
0
    private void LateUpdate()
    {
        var isSpriteFlipped = playerAnimator.getSpriteFlip();
        var spriteRen       = GetComponent <SpriteRenderer>();

        spriteRen.sprite   = weaponInventory.GetGunSprite();
        transform.position = (isSpriteFlipped)? leftTransform.position : rightTransform.position;
        var gunDir = ((Vector3)(cam.GetMousePosition() - (Vector2)transform.position)).normalized;

        spriteRen.flipX = gunDir.x < 0;

        var animGunDir = gunDir;

        if (gunDir.x < 0)
        {
            animGunDir.x = gunDir.y;
            animGunDir.y = -gunDir.x;
        }

        transform.rotation = Quaternion.FromToRotation(new Vector3(1, 1, 0), animGunDir);
    }
コード例 #3
0
 public override void Run(Projectile proj)
 {
     //If time to add another link
     if (proj.currentLifeTime / linkSpeed > links.Count)
     {
         Vector3 mousePos = cam.GetMousePosition();
         Vector3 linkPos  = proj.transform.position;
         //Set position at end of last link
         if (links.Count > 0)
         {
             GameObject lastLink = links[links.Count - 1];
             Vector3    distance = new Vector3(lastLink.GetComponentInChildren <SpriteRenderer>().bounds.size.x, 0, 0);
             distance = lastLink.transform.rotation * distance;
             linkPos  = lastLink.transform.position + distance;
         }
         //Shoot link as stationary projectile
         Projectile newLink = Projectile.Shoot(WhipLink, linkPos, mousePos);
         newLink.source = proj.source;
         newLink.transform.SetParent(proj.transform);
         links.Add(newLink.gameObject);
     }
 }
コード例 #4
0
 public Vector2 getCamMousePos()
 {
     return(cam.GetMousePosition());
 }