Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
The modifier 'private' is not valid for this item
using System.Collections; using System.Collections.Generic; using UnityEngine; public enum PlayerState { attack, walk } public class PlayerMovement : MonoBehaviour { public float speed; private Rigidbody2D myRigidbody; private Vector3 change; private Animator animator; // Start is called before the first frame update void Start() { animator = GetComponent<Animator>(); myRigidbody = GetComponent<Rigidbody2D>(); } // Update is called once per frame void Update() { change = Vector3.zero; change.x = Input.GetAxisRaw("Horizontal"); change.y = Input.GetAxisRaw("Vertical"); if (Input.GetButtonDown("attack") && currentState != PlayerState.attack) { StartCoroutine(AttackCo()); } else if (currentState == PlayerState.walk) { UpdateAnimationAndMove(); } private IEnumerator AttackCo() { animator.SetBool("attacking", true); currentState = PlayerState.attack; yield return null; animator.SetBool("attacking", false); yield return new WaitForSeconds(.33f); currentState = PlayerState.walk } void UpdateAnimationAndMove() { if (change != Vector3.zero) { MoveCharacter(); animator.SetFloat("moveX", change.x); animator.SetFloat("moveY", change.y); animator.SetBool("moving", true); } else { animator.SetBool("moving", false); } } } void MoveCharacter() { myRigidbody.MovePosition( transform.position + change * speed * Time.deltaTime ); } }
run
|
edit
|
history
|
help
0
Plt-D v.0.9
cs002
Event .net guidelines
OneDrive Direct Download Generator
Reverse linked list iterative method
aba
select z kolekcji w kolekcji (np. dokumenty i pizycje)
test
TrzyKreski
pyramidalt