hey…,
does anyone of you guys have an idea? i’m trying to set ‘FIST’ as a default. so the player starts with it automatically from the beginning.
right now, i have to put ‘1’ first and my player starts imediately to throw a punch. would love to get rid of that. just don’t know how…
hopefully you can help out.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public enum PlayerWeaponType { FIST, KNIFE, SHOTGUN };
public Animator animator;
PlayerWeaponType currentWeapon = PlayerWeaponType.FIST;
/* void Awake()
{
playerRigidbody = GetComponent<Rigidbody2D>();
//SetWeapon(PlayerWeaponType.FIST);
Debug.Log(currentWeapon);
}*/
void FixedUpdate()
{
SetWeapon();
Attack();
}
void SetWeapon()
{
if (Input.GetKeyDown("1"))
{
currentWeapon = PlayerWeaponType.FIST;
Debug.Log("FIST");
animator.SetBool("PlayerFistIdle", true);
animator.SetBool("PlayerKnifeIdle", false);
animator.SetBool("PlayerShotgunIdle", false);
}
if (Input.GetKeyDown("2"))
{
currentWeapon = PlayerWeaponType.KNIFE;
Debug.Log("KNIFE");
animator.SetBool("PlayerFistIdle", false);
animator.SetBool("PlayerKnifeIdle", true);
animator.SetBool("PlayerShotgunIdle", false);
}
if (Input.GetKeyDown("3"))
{
currentWeapon = PlayerWeaponType.SHOTGUN;
Debug.Log("SHOTGUN");
animator.SetBool("PlayerFistIdle", false);
animator.SetBool("PlayerKnifeIdle", false);
animator.SetBool("PlayerShotgunIdle", true);
}
}
void Attack()
{
if (Input.GetMouseButtonDown(0))
{
switch(currentWeapon)
{
case PlayerWeaponType.FIST:
Debug.Log("Fist");
animator.SetTrigger("PlayerPunching");
break;
case PlayerWeaponType.KNIFE:
Debug.Log("Knife");
animator.SetTrigger("PlayerKnifing");
break;
case PlayerWeaponType.SHOTGUN:
Debug.Log("Shotgun");
animator.SetTrigger("PlayerShotguning");
break;
}
}
}
}
thx a lot in advance.