when i jump to pick up the “Puck Ups” it stop the sec it hit it
New to code and unity.
if anyone know i love to get some help on this.
will add my code here.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Player : MonoBehaviour {
private Rigidbody2D myRigidbody;
private Animator myAnimator;
[SerializeField]
private Transform FireBallPros;
[SerializeField]
private float movementSpeed;
private SpriteRenderer spriteRenderer;
private bool attack;
private bool fire;
private bool faceingRight;
[SerializeField]
private Transform[ ] groundPoints;
[SerializeField]
private float groundRadius;
[SerializeField]
private LayerMask whatIsGround;
private bool isGrounded;
private bool jump;
private bool jumpjump;
[SerializeField]
private bool airControl;
[SerializeField]
private float jumpForce;
[SerializeField]
private GameObject knifePrefab;
private bool immortal = false;
[SerializeField]
private float immortalTime;
public int currentPlayerHealth;
public int maxPlayerHealth;
public Image healthBar;
// Use this for initialization
void Start()
{
spriteRenderer = GetComponent();
faceingRight = true;
myRigidbody = GetComponent();
myAnimator = GetComponent();
currentPlayerHealth = maxPlayerHealth;
}
void Update()
{
HandleInput();
healthBar.fillAmount = (float)currentPlayerHealth / maxPlayerHealth;
}
// Update is called once per frame
void FixedUpdate()
{
float horizontal = Input.GetAxis(“Horizontal”);
isGrounded = IsGrounded();
HandleMovement(horizontal);
Flip(horizontal);
HandleAttacks();
ResetValuse();
if (currentPlayerHealth <= 0)
{
Die();
}
}
//how we move
private void HandleMovement(float horizontal)
{
myRigidbody.velocity = new Vector2(horizontal * movementSpeed, myRigidbody.velocity.y);
myAnimator.SetFloat(“speed”, Mathf.Abs(horizontal));
if (isGrounded && jump)
{
isGrounded = false;
myRigidbody.AddForce(new Vector2(0, jumpForce));
}
}
//Animotor attack / fireball
private void HandleAttacks()
{
if (attack && !this.myAnimator.GetCurrentAnimatorStateInfo(0).IsTag(“Attack”))
{
myAnimator.SetTrigger(“attack”);
myRigidbody.velocity = Vector2.zero;
}
if (fire && !this.myAnimator.GetCurrentAnimatorStateInfo(0).IsTag(“Fire”))
{
myAnimator.SetTrigger(“fire”);
myRigidbody.velocity = Vector2.zero;
}
}
// Click Key to do stuff
private void HandleInput()
{
if (Input.GetKeyDown(KeyCode.Space))
{
jump = true;
}
if (Input.GetKeyDown(KeyCode.K))
{
attack = true;
}
if (Input.GetKeyDown(KeyCode.J))
{
fire = true;
ThrowKnife(0);
}
if (Input.GetKeyDown(KeyCode.H))
{
ThrowKnife(0);
}
}
//will flip you when you move to look the way you walk
private void Flip(float horizontal)
{
if (horizontal > 0 && !faceingRight || horizontal < 0 && faceingRight)
{
faceingRight = !faceingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
private void ResetValuse()
{
attack = false;
jump = false;
fire = false;
}
//can see if you are on the Ground
private bool IsGrounded()
{
if (myRigidbody.velocity.y <= 0)
{
foreach (Transform point in groundPoints)
{
Collider2D[ ] colliders = Physics2D.OverlapCircleAll(point.position, groundRadius, whatIsGround);
for (int i = 0; i < colliders.Length; i++)
{
if (colliders*.gameObject != gameObject)*
{
return true;
}
}
}
}
return false;
}
//Fire Ball Throw
public void ThrowKnife(int value)
{
if (faceingRight)
{
GameObject tmp = (GameObject)Instantiate(knifePrefab, FireBallPros.position, Quaternion.Euler(new Vector3(0,0,-90)));
tmp.GetComponent().Initialize(Vector2.right);
}
else
{
GameObject tmp = (GameObject)Instantiate(knifePrefab, FireBallPros.position, Quaternion.Euler(new Vector3(0, 0, 90)));
tmp.GetComponent().Initialize(Vector2.left);
}
}
void Die()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
public void TakeDamage(int dmg)
{
currentPlayerHealth -= dmg;
}
public void GiveDamage(int dmg)
{
if (currentPlayerHealth <= 3)
{
myAnimator.SetTrigger(“pickup”);
myRigidbody.velocity = Vector2.zero;
}
if (currentPlayerHealth <= 2)
{
currentPlayerHealth += dmg;
}
if (currentPlayerHealth <= 1)
{
currentPlayerHealth += dmg;
}
}
}