mirror of
https://github.com/ConjureETS/PixelSphinx.git
synced 2026-03-24 02:20:58 +00:00
character animation - idle, walk, dash, spin
This commit is contained in:
parent
b714044b32
commit
6f39d6f841
@ -1,22 +1,24 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections;
|
||||
|
||||
[RequireComponent(typeof(AstronautAnimator))]
|
||||
public class Astronaut : MonoBehaviour {
|
||||
|
||||
private enum AstronautState
|
||||
private AstronautAnimator _astronautAnimator;
|
||||
public enum AstronautState
|
||||
{
|
||||
Idle, Walking, Jumping, Dashing, Ejecting, Dead
|
||||
}
|
||||
|
||||
public GameObject Rotator;
|
||||
public GameObject SpriteWalk;
|
||||
public SpriteRenderer SpriteWalk;
|
||||
public GameObject SpriteDash;
|
||||
|
||||
public float StepTime;
|
||||
public float JumpSpeed;
|
||||
|
||||
private AstronautState _state;
|
||||
private AstronautState State
|
||||
public AstronautState State
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -30,19 +32,20 @@ public class Astronaut : MonoBehaviour {
|
||||
if (oldState == _state) return;
|
||||
|
||||
if (oldState == AstronautState.Dashing)
|
||||
{
|
||||
SpriteWalk.SetActive(false);
|
||||
SpriteDash.SetActive(true);
|
||||
{
|
||||
SpriteWalk.gameObject.SetActive(true);
|
||||
SpriteDash.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
SpriteWalk.SetActive(true);
|
||||
SpriteDash.SetActive(false);
|
||||
{
|
||||
SpriteWalk.gameObject.SetActive(true);
|
||||
SpriteDash.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
|
||||
if (_state == AstronautState.Walking)
|
||||
{
|
||||
StartCoroutine(WalkingStance());
|
||||
//StartCoroutine(WalkingStance());
|
||||
_astronautAnimator.Walk();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -53,8 +56,11 @@ public class Astronaut : MonoBehaviour {
|
||||
private float walkTime = 0;
|
||||
private int nextStep = 1;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
_astronautAnimator = GetComponent<AstronautAnimator>();
|
||||
_astronautAnimator.aspi = this;
|
||||
State = AstronautState.Idle;
|
||||
}
|
||||
|
||||
@ -115,6 +121,7 @@ public class Astronaut : MonoBehaviour {
|
||||
{
|
||||
if (_state >= AstronautState.Ejecting)
|
||||
return;
|
||||
_astronautAnimator.Jump();
|
||||
}
|
||||
|
||||
public void Dash()
|
||||
@ -125,10 +132,32 @@ public class Astronaut : MonoBehaviour {
|
||||
|
||||
public void OnGUI()
|
||||
{
|
||||
if (GUI.Button(new Rect(10, 10, 150, 50), State.ToString()))
|
||||
Debug.Log("Clicked the button with an image");
|
||||
}
|
||||
if (GUI.Button(new Rect(10, 10, 150, 50), "Jump"))
|
||||
{
|
||||
Debug.Log("Clicked the button with an image");
|
||||
_astronautAnimator.Jump();
|
||||
}
|
||||
|
||||
if (GUI.Button(new Rect(10, 70, 150, 50), "Land"))
|
||||
{
|
||||
Debug.Log("Clicked the 2nd button");
|
||||
_astronautAnimator.Land();
|
||||
}
|
||||
|
||||
if (GUI.Button(new Rect(10, 130, 150, 50), "Walk"))
|
||||
{
|
||||
Debug.Log("Clicked the 3rd button");
|
||||
State = AstronautState.Walking;
|
||||
_astronautAnimator.Walk();
|
||||
}
|
||||
|
||||
if (GUI.Button(new Rect(10, 190, 150, 50), "Eject"))
|
||||
{
|
||||
Debug.Log("Clicked the 4th button");
|
||||
_astronautAnimator.Eject();
|
||||
}
|
||||
}
|
||||
/*
|
||||
IEnumerator WalkingStance()
|
||||
{
|
||||
Debug.Log("walking stance");
|
||||
@ -137,7 +166,7 @@ public class Astronaut : MonoBehaviour {
|
||||
{
|
||||
Vector3 rotation = transform.rotation.eulerAngles;
|
||||
rotation.z = Mathf.Sin(walkTime*Mathf.PI)*50;
|
||||
print("rotation " + rotation);
|
||||
//print("rotation " + rotation);
|
||||
transform.rotation = Quaternion.Euler(rotation);
|
||||
yield return null;
|
||||
}
|
||||
@ -147,5 +176,5 @@ public class Astronaut : MonoBehaviour {
|
||||
{
|
||||
StartCoroutine("WalkingStance");
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
75
Assets/Scripts/AstronautAnimator.cs
Normal file
75
Assets/Scripts/AstronautAnimator.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class AstronautAnimator : MonoBehaviour {
|
||||
|
||||
//init
|
||||
public Astronaut aspi;
|
||||
public float WalkAnimSpeed;
|
||||
public float WalkAnimAngle;
|
||||
public float EjectSpinSpeed;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
|
||||
public void Jump()
|
||||
{
|
||||
aspi.SpriteWalk.gameObject.SetActive(false);
|
||||
aspi.SpriteDash.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void Land()
|
||||
{
|
||||
aspi.SpriteWalk.gameObject.SetActive(true);
|
||||
aspi.SpriteDash.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void Walk()
|
||||
{
|
||||
StartCoroutine(Rotate());
|
||||
}
|
||||
|
||||
public void Eject()
|
||||
{
|
||||
StartCoroutine(Spin());
|
||||
}
|
||||
|
||||
IEnumerator Spin()
|
||||
{
|
||||
for (float i = 0f; i < 3000f; i += Time.deltaTime * EjectSpinSpeed)
|
||||
{
|
||||
transform.rotation = Quaternion.Euler(0, 0, i);
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator Rotate()
|
||||
{
|
||||
for (float i = 0.5f; i < 2.5f; i+= Time.deltaTime*WalkAnimSpeed)
|
||||
{
|
||||
/*int roundDown = 10;
|
||||
//0.5, 1.5 et 2.5
|
||||
if (Mathf.Floor(i * roundDown) == roundDown || Mathf.Floor(i * roundDown) == 2 * roundDown)
|
||||
{
|
||||
print(i * roundDown + " " + Mathf.Floor(i * roundDown));
|
||||
aspi.SpriteWalk.flipX = !aspi.SpriteWalk.flipX;
|
||||
}*/
|
||||
float position = Mathf.PingPong(i, 1f);
|
||||
transform.rotation = Quaternion.Euler(0, 0, (position - 0.5f) * WalkAnimAngle * 2);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if (aspi.State == Astronaut.AstronautState.Walking)
|
||||
{
|
||||
StartCoroutine(Rotate());
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
12
Assets/Scripts/AstronautAnimator.cs.meta
Normal file
12
Assets/Scripts/AstronautAnimator.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77462b2431858f84b9bc2d055c2f4d45
|
||||
timeCreated: 1460135550
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
70
Assets/Scripts/AstronautController2.cs
Normal file
70
Assets/Scripts/AstronautController2.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using InputHandler;
|
||||
|
||||
[RequireComponent(typeof(Astronaut))]
|
||||
public class AstronautController2 : MonoBehaviour
|
||||
{
|
||||
|
||||
private Astronaut _astronaut;
|
||||
|
||||
public int PlayerNumber;
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
InputManager.Instance.PushActiveContext("Gameplay", PlayerNumber);
|
||||
InputManager.Instance.AddCallback(PlayerNumber, HandlePlayerAxis);
|
||||
InputManager.Instance.AddCallback(PlayerNumber, HandlePlayerButtons);
|
||||
|
||||
_astronaut = GetComponent<Astronaut>();
|
||||
}
|
||||
|
||||
private void HandlePlayerAxis(MappedInput input)
|
||||
{
|
||||
if (this == null) return;
|
||||
|
||||
// movement
|
||||
|
||||
float xValue = 0f;
|
||||
|
||||
if (input.Ranges.ContainsKey("MoveLeft"))
|
||||
{
|
||||
xValue = -input.Ranges["MoveLeft"];
|
||||
}
|
||||
else if (input.Ranges.ContainsKey("MoveRight"))
|
||||
{
|
||||
xValue = input.Ranges["MoveRight"];
|
||||
}
|
||||
|
||||
float yValue = 0f;
|
||||
|
||||
if (input.Ranges.ContainsKey("MoveUp"))
|
||||
{
|
||||
yValue = input.Ranges["MoveUp"];
|
||||
}
|
||||
else if (input.Ranges.ContainsKey("MoveDown"))
|
||||
{
|
||||
yValue = -input.Ranges["MoveDown"];
|
||||
}
|
||||
|
||||
_astronaut.Move(xValue, yValue);
|
||||
|
||||
if (input.Ranges.ContainsKey("Dash"))
|
||||
{
|
||||
if (input.Ranges["Dash"] > 0.8f)
|
||||
_astronaut.Dash();
|
||||
}
|
||||
}
|
||||
|
||||
private void HandlePlayerButtons(MappedInput input)
|
||||
{
|
||||
if (this == null) return;
|
||||
|
||||
if (input.Actions.Contains("Jump"))
|
||||
{
|
||||
_astronaut.Jump();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
Assets/Scripts/AstronautController2.cs.meta
Normal file
12
Assets/Scripts/AstronautController2.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7792093ffcd687448b5875a8ce0cc32
|
||||
timeCreated: 1460133633
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -12,7 +12,7 @@ public class PlanetManager : MonoBehaviour
|
||||
public bool CartierResetRatioSpeedRandomize = true;
|
||||
public float CartierMinRatio = 0.4f;
|
||||
public float CartierMaxRatio = 2.0f;
|
||||
public float CartierStepSize = 0.25;
|
||||
public float CartierStepSize = 0.25f;
|
||||
public GameObject WedgePrefab = null;
|
||||
public List<Wedge> wedges = new List<Wedge>();
|
||||
|
||||
|
||||
@ -171,6 +171,53 @@ Transform:
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
--- !u!1001 &160670874
|
||||
Prefab:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_Modification:
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications:
|
||||
- target: {fileID: 498212, guid: 158e745881137e04ca2086294f44d74c, type: 2}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: -0.6692338
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 498212, guid: 158e745881137e04ca2086294f44d74c, type: 2}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: 1.7862048
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 498212, guid: 158e745881137e04ca2086294f44d74c, type: 2}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: -0.045327663
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 498212, guid: 158e745881137e04ca2086294f44d74c, type: 2}
|
||||
propertyPath: m_LocalRotation.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 498212, guid: 158e745881137e04ca2086294f44d74c, type: 2}
|
||||
propertyPath: m_LocalRotation.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 498212, guid: 158e745881137e04ca2086294f44d74c, type: 2}
|
||||
propertyPath: m_LocalRotation.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 498212, guid: 158e745881137e04ca2086294f44d74c, type: 2}
|
||||
propertyPath: m_LocalRotation.w
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 498212, guid: 158e745881137e04ca2086294f44d74c, type: 2}
|
||||
propertyPath: m_RootOrder
|
||||
value: 3
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 11450178, guid: 158e745881137e04ca2086294f44d74c, type: 2}
|
||||
propertyPath: InputMapperAsset
|
||||
value:
|
||||
objectReference: {fileID: 11400000, guid: ba52e0f13249c9e46bb162622e61904f,
|
||||
type: 2}
|
||||
m_RemovedComponents: []
|
||||
m_ParentPrefab: {fileID: 100100000, guid: 158e745881137e04ca2086294f44d74c, type: 2}
|
||||
m_IsPrefabParent: 0
|
||||
--- !u!1 &238389812
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -231,44 +278,110 @@ Transform:
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 2
|
||||
--- !u!1 &1024275268
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
serializedVersion: 4
|
||||
m_Component:
|
||||
- 4: {fileID: 1024275269}
|
||||
- 114: {fileID: 1024275270}
|
||||
m_Layer: 0
|
||||
m_Name: spawnAsteroid
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &1024275269
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 1024275268}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 1
|
||||
--- !u!114 &1024275270
|
||||
--- !u!212 &841465700 stripped
|
||||
SpriteRenderer:
|
||||
m_PrefabParentObject: {fileID: 21220066, guid: acd71c7b2f995984d9033c9dc4e257dc,
|
||||
type: 2}
|
||||
m_PrefabInternal: {fileID: 1660503799}
|
||||
--- !u!1001 &1660503799
|
||||
Prefab:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_Modification:
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications:
|
||||
- target: {fileID: 494126, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 494126, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 494126, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 494126, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
propertyPath: m_LocalRotation.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 494126, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
propertyPath: m_LocalRotation.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 494126, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
propertyPath: m_LocalRotation.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 494126, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
propertyPath: m_LocalRotation.w
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 494126, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
propertyPath: m_RootOrder
|
||||
value: 2
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 403646, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
propertyPath: m_LocalScale.x
|
||||
value: 0.5
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 403646, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
propertyPath: m_LocalScale.y
|
||||
value: 0.5
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 403646, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: 3.46
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 21257324, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
propertyPath: m_Enabled
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 157058, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
propertyPath: m_IsActive
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 21220066, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
propertyPath: m_FlipX
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 11494368, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
propertyPath: SpriteWalk
|
||||
value:
|
||||
objectReference: {fileID: 841465700}
|
||||
- target: {fileID: 21220066, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
propertyPath: m_Color.r
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 21220066, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
propertyPath: m_Color.g
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 21220066, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
propertyPath: m_Color.b
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_ParentPrefab: {fileID: 100100000, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
m_IsPrefabParent: 0
|
||||
--- !u!1 &1660503800 stripped
|
||||
GameObject:
|
||||
m_PrefabParentObject: {fileID: 170392, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2}
|
||||
m_PrefabInternal: {fileID: 1660503799}
|
||||
--- !u!114 &1660503801
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 1024275268}
|
||||
m_GameObject: {fileID: 1660503800}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 665432c96ca23f140a869ed98ade0dde, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: 77462b2431858f84b9bc2d055c2f4d45, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
myAsteroid: {fileID: 160026, guid: cc1a204562630cd40a1dd685b5ed8e6e, type: 2}
|
||||
aspi: {fileID: 0}
|
||||
WalkAnimSpeed: 4
|
||||
WalkAnimAngle: 20
|
||||
EjectSpinSpeed: 60
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user