character update

This commit is contained in:
cyber-dream 2022-06-13 02:56:05 +03:00
parent ac697bf3fa
commit 1f1f44e62c
9 changed files with 90 additions and 4 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2404d8b5a589d3078ac5c4223e0b3ec0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,29 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Character : MonoBehaviour
{
[SerializeField] private CharacterData characterData;
private Rigidbody2D rigidBody;
[SerializeField] private GameObject characterSprite;
private Animator animator;
private static readonly int IsRun = Animator.StringToHash("IsRun");
public void Start()
{
rigidBody = GetComponent<Rigidbody2D>();
animator = characterSprite.GetComponent<Animator>();
}
public void Update()
{
var horInput = Input.GetAxis("Horizontal");
var verInput = Input.GetAxis("Vertical");
rigidBody.velocity = new Vector2(horInput , verInput) * characterData.moveSpeedMultiplier;
characterSprite.transform.localScale = new Vector3(horInput > 0 ? 1 : -1, 1, 1);
animator.SetBool(IsRun, Mathf.Abs(horInput) > 0 || Mathf.Abs(verInput) > 0);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 584da5b9caaf58e0da2ae26a4bbe9d02
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,27 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 65ab2b639f4ff314a962ad5a94ab058a, type: 3}
m_Name: CharacterData
m_EditorClassIdentifier:
shootableObject: {fileID: 0}
staticShootable: {fileID: 0}
meleeWeapon: {fileID: 0}
moveSpeedMultiplier: 2
crouchSpeed: 50
crouchColliderHeight: 1
normalColliderHeight: 2
rotationSpeed: 60
crouchRotationSpeed: 30
jumpForce: 10
diveForce: 30
bulletInitialSpeed: 10
diveCooldownTimer: 0.25

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4da5c8fa0351efd6c8284885156d13c6
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -29,6 +29,7 @@
*/ */
using UnityEngine; using UnityEngine;
using UnityEngine.Serialization;
[CreateAssetMenu(fileName = "CharacterData", menuName = "Game Data/Character Data")] [CreateAssetMenu(fileName = "CharacterData", menuName = "Game Data/Character Data")]
public class CharacterData : ScriptableObject public class CharacterData : ScriptableObject
@ -36,7 +37,8 @@ public class CharacterData : ScriptableObject
public GameObject shootableObject; public GameObject shootableObject;
public GameObject staticShootable; public GameObject staticShootable;
public GameObject meleeWeapon; public GameObject meleeWeapon;
public float movementSpeed = 150f; [Range(1f,5f)]
public float moveSpeedMultiplier = 1f;
public float crouchSpeed = 50f; public float crouchSpeed = 50f;
public float crouchColliderHeight = 1f; public float crouchColliderHeight = 1f;
public float normalColliderHeight = 2f; public float normalColliderHeight = 2f;

View File

@ -5,9 +5,9 @@
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
public class Character : MonoBehaviour public class Character_obsolete : MonoBehaviour
{ {
[SerializeField] private Gameplay _gameplay; //[SerializeField] private Gameplay _gameplay;
[SerializeField] private float health; [SerializeField] private float health;
[SerializeField] private float damage; [SerializeField] private float damage;
[SerializeField] private float moveSpeed; [SerializeField] private float moveSpeed;
@ -84,6 +84,7 @@ public void ApplyDamage(float damage)
{ {
health -= damage; health -= damage;
} }
/*
public float GetHealth() public float GetHealth()
{ {
return health; return health;
@ -99,5 +100,5 @@ public void SetHealth(float newHealth)
public void SetDamage(float newDamage) public void SetDamage(float newDamage)
{ {
damage = newDamage; damage = newDamage;
} }*/
} }