added animation, pickaxe, fixed lookaround

This commit is contained in:
TAASONI3
2023-12-27 10:54:16 +01:00
parent 4626722b94
commit 0865eee42f
20 changed files with 1450 additions and 550 deletions

View File

@@ -36,6 +36,39 @@ public class Controls : MonoBehaviour
// Update is called once per frame
void Update()
{
if (uihandler.state == UIState.GAME && playerInput.currentActionMap.name != "MainGame")
{
playerInput.SwitchCurrentActionMap("MainGame");
}
if (uihandler.state != UIState.GAME && playerInput.currentActionMap.name != "Menu")
{
playerInput.SwitchCurrentActionMap("Menu");
}
if (!player.GetComponent<PlayerGameObject>().takeDamage(0))
{
if (!uihandler.isPlayerInFight())
{
if (uihandler.canPlayerRotate())
{
player.GetComponent<PlayerGameObject>().lookAround(view, playerInput.currentControlScheme == "Controller");
}
if (uihandler.canPlayerMove())
{
player.GetComponent<PlayerGameObject>().move(input);
}
}
}
}
public void FixedUpdate()
{
if (direction != MoveDirection.None)
{
AxisEventData data = new AxisEventData(EventSystem.current);
data.moveDir = direction;
data.selectedObject = EventSystem.current.currentSelectedGameObject;
ExecuteEvents.Execute(data.selectedObject, data, ExecuteEvents.moveHandler);
}
if (playerInput.currentControlScheme == "Controller")
{
if (Cursor.lockState != CursorLockMode.Locked)
@@ -60,39 +93,6 @@ public class Controls : MonoBehaviour
GameObject.Find("txtInteraction_Tutorial").GetComponent<Text>().text = GameObject.Find("txtInteraction_Tutorial").GetComponent<Text>().text.Replace("[E]", "[ButtonEast]");
GameObject.Find("txtTutorialGoal").GetComponent<Text>().text = GameObject.Find("txtTutorialGoal").GetComponent<Text>().text.Replace("[Start]", "[ESC]");
}
if (uihandler.state == UIState.GAME && playerInput.currentActionMap.name != "MainGame")
{
playerInput.SwitchCurrentActionMap("MainGame");
}
if (uihandler.state != UIState.GAME && playerInput.currentActionMap.name != "Menu")
{
playerInput.SwitchCurrentActionMap("Menu");
}
if (!player.GetComponent<PlayerGameObject>().takeDamage(0))
{
if (!uihandler.isPlayerInFight())
{
if (uihandler.canPlayerRotate())
{
playerCam.GetComponent<PlayerCamera>().lookAround(view, playerInput.currentControlScheme == "Controller");
}
if (uihandler.canPlayerMove())
{
player.GetComponent<PlayerGameObject>().move(input);
}
}
}
}
public void FixedUpdate()
{
if (direction != MoveDirection.None)
{
AxisEventData data = new AxisEventData(EventSystem.current);
data.moveDir = direction;
data.selectedObject = EventSystem.current.currentSelectedGameObject;
ExecuteEvents.Execute(data.selectedObject, data, ExecuteEvents.moveHandler);
}
}
public void OnLooking(InputValue value)
@@ -145,8 +145,8 @@ public class Controls : MonoBehaviour
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Wood"));
break;
case "Stone":
StartCoroutine(playAnimation(target, "Mining"));
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Rock"));
Destroy(target);
break;
case "NPC":
target.GetComponent<NPC>().interact();
@@ -194,6 +194,24 @@ public class Controls : MonoBehaviour
Destroy(target);
}
IEnumerator playAnimation(GameObject target, string key)
{
player.GetComponent<Animator>().Play(key);
Animator animator = player.GetComponent<Animator>();
AnimationClip[] clips = animator.runtimeAnimatorController.animationClips;
float length = 0;
foreach (AnimationClip clip in clips)
{
if (clip.name.ToLower() == key.ToLower())
{
length = clip.length;
break;
}
}
yield return new WaitForSeconds(length);
Destroy(target);
}
public void OnInventory()
{
uihandler.switchInventory();