void StartShootingWithTheMouse() { if (firePoint == null) { Debug.Log("FirePoint not found, why?!?"); } mousePosition = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y); firePointPosition = new Vector2(firePoint.position.x, firePoint.position.y); RaycastHit2D hit = Physics2D.Raycast(firePointPosition, mousePosition - firePointPosition, 100, notToHit); GameObject newBall = Instantiate(Ball, firePoint.position, firePoint.rotation); var newBallRigidbody = newBall.GetComponent <Rigidbody2D>(); newBallRigidbody.angularVelocity *= shootingForce; switch (inkBehaviour.ammoType) { case InkBehaviour.AmmoType.Bouncy: if (PS.CurrentBouncyAmmo != 0) { newBall.GetComponent <SpriteRenderer>().color = BouncyColour; PS.CurrentBouncyAmmo--; } else if (PS.CurrentBouncyAmmo == 0) { ammoType = InkBehaviour.AmmoType.Clear; Debug.Log("No Bouncy ammo!"); } break; case InkBehaviour.AmmoType.Speedy: newBall.GetComponent <SpriteRenderer>().color = SpeedyColour; break; case InkBehaviour.AmmoType.Sticky: newBall.GetComponent <SpriteRenderer>().color = StickyColour; break; case InkBehaviour.AmmoType.Clear: newBall.GetComponent <SpriteRenderer>().color = ClearColour; break; } newBall.GetComponent <Rigidbody2D>().AddForce(transform.right * FiringForce); }
void StartShooting() { firePoint = transform.Find("PlayerFirePoint"); //Anim.SetInteger("State", 5); GameObject newBall = Instantiate(Ball, firePoint.position, firePoint.rotation); switch (inkBehaviour.ammoType) { case InkBehaviour.AmmoType.Bouncy: if (PS.CurrentBouncyAmmo != 0) { newBall.GetComponent <SpriteRenderer>().color = BouncyColour; PS.CurrentBouncyAmmo--; } else if (PS.CurrentBouncyAmmo == 0) { ammoType = InkBehaviour.AmmoType.Clear; Debug.Log("No Bouncy ammo!"); } break; case InkBehaviour.AmmoType.Speedy: newBall.GetComponent <SpriteRenderer>().color = SpeedyColour; break; case InkBehaviour.AmmoType.Sticky: newBall.GetComponent <SpriteRenderer>().color = StickyColour; break; case InkBehaviour.AmmoType.Clear: newBall.GetComponent <SpriteRenderer>().color = ClearColour; break; } newBall.GetComponent <Rigidbody2D>().AddForce(transform.right * FiringForce); }