added animation, pickaxe, fixed lookaround
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -20,7 +20,7 @@ public class Fight : MonoBehaviour
|
||||
this.enemy = enemy;
|
||||
this.player = player;
|
||||
enemy.GetComponent<Enemy>().scaleEnemy(player.GetComponent<PlayerGameObject>());
|
||||
enemy.transform.rotation = Quaternion.Euler(0, GameObject.Find("Main Camera").transform.rotation.y + 180f, 0);
|
||||
enemy.transform.rotation = Quaternion.Euler(0, player.transform.rotation.y + 180f, 0);
|
||||
|
||||
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandler>();
|
||||
uihandler.openFight();
|
||||
|
||||
@@ -85,8 +85,8 @@ namespace Assets.Scripts
|
||||
saveText = saveText + uihandler.saveVideoSettings() + "\r\n";
|
||||
saveText = saveText + uihandler.saveLanguage() + "\r\n";
|
||||
saveText = saveText + audioHandler.saveAudioSettings() + "\r\n";
|
||||
GameObject.Find("Main Camera").GetComponent<PlayerCamera>().mouseSpeed = GameObject.Find("slideSensitivityMouse").GetComponent<Slider>().value;
|
||||
GameObject.Find("Main Camera").GetComponent<PlayerCamera>().controllerSpeed = GameObject.Find("slideSensitivityController").GetComponent<Slider>().value;
|
||||
GameObject.Find("Player").GetComponent<PlayerGameObject>().mouseSpeed = GameObject.Find("slideSensitivityMouse").GetComponent<Slider>().value;
|
||||
GameObject.Find("Player").GetComponent<PlayerGameObject>().controllerSpeed = GameObject.Find("slideSensitivityController").GetComponent<Slider>().value;
|
||||
saveText = saveText + "SensitivityMouse:"+GameObject.Find("slideSensitivityMouse").GetComponent<Slider>().value + "\r\n";
|
||||
saveText = saveText + "SensitivityController:"+GameObject.Find("slideSensitivityController").GetComponent<Slider>().value;
|
||||
FileHandler.saveOptions(saveText);
|
||||
|
||||
@@ -104,12 +104,12 @@ namespace Assets.Scripts
|
||||
break;
|
||||
case "SensitivityMouse":
|
||||
if(isIngame){
|
||||
GameObject.Find("Main Camera").GetComponent<PlayerCamera>().mouseSpeed = float.Parse(line.Split(':')[1]);
|
||||
GameObject.Find("Player").GetComponent<PlayerGameObject>().mouseSpeed = float.Parse(line.Split(':')[1]);
|
||||
}
|
||||
break;
|
||||
case "SensitivityController":
|
||||
if(isIngame){
|
||||
GameObject.Find("Main Camera").GetComponent<PlayerCamera>().controllerSpeed = float.Parse(line.Split(':')[1]);
|
||||
GameObject.Find("Player").GetComponent<PlayerGameObject>().controllerSpeed = float.Parse(line.Split(':')[1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -8,19 +8,12 @@ namespace Assets.Scripts.Player
|
||||
public class PlayerCamera : MonoBehaviour
|
||||
{
|
||||
UIHandler uihandler;
|
||||
GameObject player;
|
||||
Vector2 rotation = Vector2.zero;
|
||||
public float mouseSpeed = 100; //the sensibility
|
||||
public float controllerSpeed = 0.01f; //the sensibility
|
||||
float xMaxLimit = 50.0f;
|
||||
float xMinLimit = -50.0f;
|
||||
GameObject interact;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandler>();
|
||||
player = gameObject.transform.parent.gameObject;
|
||||
interact = GameObject.Find("pnlInteract");
|
||||
interact.transform.localScale = new Vector3(0, 0, 0);
|
||||
}
|
||||
@@ -29,7 +22,6 @@ namespace Assets.Scripts.Player
|
||||
void Update()
|
||||
{
|
||||
transform.position = new Vector3(transform.parent.transform.position.x, transform.position.y, transform.parent.transform.position.z);
|
||||
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
@@ -37,22 +29,6 @@ namespace Assets.Scripts.Player
|
||||
showInformation();
|
||||
}
|
||||
|
||||
public void lookAround(Vector2 view, bool isController)
|
||||
{
|
||||
rotation.y += view.x;
|
||||
rotation.x += -view.y;
|
||||
//rotation.x = Mathf.Clamp(rotation.x, xMinLimit, xMaxLimit);
|
||||
if (isController)
|
||||
{
|
||||
transform.eulerAngles = rotation * (controllerSpeed * Time.deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.eulerAngles = rotation * mouseSpeed;
|
||||
//TODO: Look at camera movement -> Not rly smooth. Weird drag
|
||||
}
|
||||
}
|
||||
|
||||
public GameObject interactWithObject()
|
||||
{
|
||||
RaycastHit hit;
|
||||
|
||||
@@ -25,6 +25,11 @@ namespace Assets.Scripts.Player
|
||||
DateTime jumpTimer;
|
||||
DateTime now;
|
||||
int bobbingDirection = -1;
|
||||
public float mouseSpeed = 100; //the sensibility
|
||||
public float controllerSpeed = 0.01f; //the sensibility
|
||||
float xMaxLimit = 45.0f;
|
||||
float xMinLimit = -45.0f;
|
||||
Vector2 rotation = Vector2.zero;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
@@ -157,8 +162,6 @@ namespace Assets.Scripts.Player
|
||||
}
|
||||
|
||||
Vector3 movement = new Vector3(input.x, 0, input.z);
|
||||
movement = camera.transform.TransformDirection(movement);
|
||||
movement.y = 0;
|
||||
gameObject.transform.Translate(movement * speed * Time.deltaTime);
|
||||
|
||||
if (input.z != 0)
|
||||
@@ -180,7 +183,7 @@ namespace Assets.Scripts.Player
|
||||
public void getRotation()
|
||||
{
|
||||
GameObject needle = GameObject.Find("imgNeedle");
|
||||
float rotation = GameObject.Find("Main Camera").transform.rotation.eulerAngles.y;
|
||||
float rotation = gameObject.transform.rotation.eulerAngles.y;
|
||||
if (rotation < 0)
|
||||
{
|
||||
rotation += 360;
|
||||
@@ -218,19 +221,21 @@ namespace Assets.Scripts.Player
|
||||
{
|
||||
worldGenerator.changeCurrentTile(col.gameObject);
|
||||
|
||||
worldGenerator.createTile(new Vector3(-1,0,0));
|
||||
worldGenerator.createTile(new Vector3(1,0,0));
|
||||
worldGenerator.createTile(new Vector3(0,0,1));
|
||||
worldGenerator.createTile(new Vector3(0,0,-1));
|
||||
worldGenerator.createTile(new Vector3(-1, 0, 0));
|
||||
worldGenerator.createTile(new Vector3(1, 0, 0));
|
||||
worldGenerator.createTile(new Vector3(0, 0, 1));
|
||||
worldGenerator.createTile(new Vector3(0, 0, -1));
|
||||
|
||||
worldGenerator.createTile(new Vector3(-1,0,-1));
|
||||
worldGenerator.createTile(new Vector3(1,0,-1));
|
||||
worldGenerator.createTile(new Vector3(-1,0,1));
|
||||
worldGenerator.createTile(new Vector3(1,0,1));
|
||||
worldGenerator.createTile(new Vector3(-1, 0, -1));
|
||||
worldGenerator.createTile(new Vector3(1, 0, -1));
|
||||
worldGenerator.createTile(new Vector3(-1, 0, 1));
|
||||
worldGenerator.createTile(new Vector3(1, 0, 1));
|
||||
}
|
||||
|
||||
if(col.name.Contains("House")){
|
||||
if(!col.transform.Find("Door").GetComponent<Door>().hasInteracted){
|
||||
if (col.name.Contains("House"))
|
||||
{
|
||||
if (!col.transform.Find("Door").GetComponent<Door>().hasInteracted)
|
||||
{
|
||||
transform.position = new Vector3(transform.position.x + 10, 10, transform.position.z);
|
||||
}
|
||||
}
|
||||
@@ -349,7 +354,8 @@ namespace Assets.Scripts.Player
|
||||
{
|
||||
if (player != null)
|
||||
{
|
||||
if(player.takeDamage(amount, inventory.getEquipmentBonus()["DEX"], inventory.getEquipmentBonus()["INT"])){
|
||||
if (player.takeDamage(amount, inventory.getEquipmentBonus()["DEX"], inventory.getEquipmentBonus()["INT"]))
|
||||
{
|
||||
audioHandler.playDamage();
|
||||
return true;
|
||||
}
|
||||
@@ -360,7 +366,8 @@ namespace Assets.Scripts.Player
|
||||
public int castSkill(int skillnumber)
|
||||
{
|
||||
int damage = player.castSkill(skillnumber, inventory.getEquipmentBonus()["INT"], inventory.getEquipmentBonus()["STR"], inventory.getEquipmentBonus()["DEX"]);
|
||||
if(damage > 0){
|
||||
if (damage > 0)
|
||||
{
|
||||
player.getSkill(skillnumber).playSound(audioHandler);
|
||||
}
|
||||
return damage;
|
||||
@@ -375,5 +382,21 @@ namespace Assets.Scripts.Player
|
||||
{
|
||||
player.regainSecondary(inventory.getEquipmentBonus()["MPR"], inventory.getEquipmentBonus()["MP"]);
|
||||
}
|
||||
|
||||
public void lookAround(Vector2 view, bool isController)
|
||||
{
|
||||
rotation.y += view.x;
|
||||
rotation.x += -view.y;
|
||||
rotation.x = Mathf.Clamp(rotation.x, xMinLimit, xMaxLimit);
|
||||
if (isController)
|
||||
{
|
||||
transform.eulerAngles = rotation * (controllerSpeed * Time.deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.eulerAngles = rotation * mouseSpeed;
|
||||
//TODO: Look at camera movement -> Not rly smooth. Weird drag
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user