Working logic's changes into my own stuff

This commit is contained in:
2018-04-22 15:10:35 +10:00
parent f2c1587be4
commit db0b719158
2 changed files with 247 additions and 70 deletions
+235 -27
View File
@@ -6279,6 +6279,68 @@ Prefab:
m_RemovedComponents: [] m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 05968d49eff9aa04b9087b76d2a70f50, type: 2} m_ParentPrefab: {fileID: 100100000, guid: 05968d49eff9aa04b9087b76d2a70f50, type: 2}
m_IsPrefabParent: 0 m_IsPrefabParent: 0
--- !u!1 &773408882
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 773408885}
- component: {fileID: 773408884}
- component: {fileID: 773408883}
m_Layer: 0
m_Name: EventSystem
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &773408883
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 773408882}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1077351063, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalAxis: Horizontal
m_VerticalAxis: Vertical
m_SubmitButton: Submit
m_CancelButton: Cancel
m_InputActionsPerSecond: 10
m_RepeatDelay: 0.5
m_ForceModuleActive: 0
--- !u!114 &773408884
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 773408882}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -619905303, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_FirstSelected: {fileID: 0}
m_sendNavigationEvents: 1
m_DragThreshold: 5
--- !u!4 &773408885
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 773408882}
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: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &805842225 --- !u!1001 &805842225
Prefab: Prefab:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -6767,6 +6829,100 @@ Prefab:
m_RemovedComponents: [] m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 55b556ac6e46dbb4abdebeb341e45cce, type: 2} m_ParentPrefab: {fileID: 100100000, guid: 55b556ac6e46dbb4abdebeb341e45cce, type: 2}
m_IsPrefabParent: 0 m_IsPrefabParent: 0
--- !u!1 &921564294
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 921564298}
- component: {fileID: 921564297}
- component: {fileID: 921564296}
- component: {fileID: 921564295}
m_Layer: 5
m_Name: Canvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &921564295
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 921564294}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1301386320, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295
--- !u!114 &921564296
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 921564294}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1980459831, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
--- !u!223 &921564297
Canvas:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 921564294}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 1
m_Camera: {fileID: 1089679580}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 0
m_SortingLayerID: 1108410147
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!224 &921564298
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 921564294}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 1290387091}
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!4 &947997572 stripped --- !u!4 &947997572 stripped
Transform: Transform:
m_PrefabParentObject: {fileID: 4727204445767746, guid: 05968d49eff9aa04b9087b76d2a70f50, m_PrefabParentObject: {fileID: 4727204445767746, guid: 05968d49eff9aa04b9087b76d2a70f50,
@@ -9734,6 +9890,84 @@ Transform:
m_PrefabParentObject: {fileID: 4890223527033060, guid: 55b556ac6e46dbb4abdebeb341e45cce, m_PrefabParentObject: {fileID: 4890223527033060, guid: 55b556ac6e46dbb4abdebeb341e45cce,
type: 2} type: 2}
m_PrefabInternal: {fileID: 1243072168} m_PrefabInternal: {fileID: 1243072168}
--- !u!1 &1290387090
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1290387091}
- component: {fileID: 1290387093}
- component: {fileID: 1290387092}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1290387091
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1290387090}
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: 921564298}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 80, y: -15}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1290387092
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1290387090}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 1
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 'Move: WASD
Shoot: Space
Change: E'
--- !u!222 &1290387093
CanvasRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1290387090}
--- !u!1001 &1300898991 --- !u!1001 &1300898991
Prefab: Prefab:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -10322,7 +10556,6 @@ GameObject:
- component: {fileID: 1602044334} - component: {fileID: 1602044334}
- component: {fileID: 1602044333} - component: {fileID: 1602044333}
- component: {fileID: 1602044331} - component: {fileID: 1602044331}
- component: {fileID: 1602044330}
- component: {fileID: 1602044329} - component: {fileID: 1602044329}
- component: {fileID: 1602044335} - component: {fileID: 1602044335}
- component: {fileID: 1602044332} - component: {fileID: 1602044332}
@@ -10350,31 +10583,6 @@ MonoBehaviour:
type: 2} type: 2}
windPelletPrefab: {fileID: 1389927462137108, guid: 407acfcef7e27af47a3df873b629b4a4, windPelletPrefab: {fileID: 1389927462137108, guid: 407acfcef7e27af47a3df873b629b4a4,
type: 2} type: 2}
--- !u!61 &1602044330
BoxCollider2D:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1602044328}
m_Enabled: 0
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 0.32, y: 0.32}
newSize: {x: 0.32, y: 0.32}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 0.12, y: 0.12}
m_EdgeRadius: 0
--- !u!50 &1602044331 --- !u!50 &1602044331
Rigidbody2D: Rigidbody2D:
serializedVersion: 4 serializedVersion: 4
@@ -10446,7 +10654,7 @@ SpriteRenderer:
m_SortingLayerID: -1935211587 m_SortingLayerID: -1935211587
m_SortingLayer: 3 m_SortingLayer: 3
m_SortingOrder: 0 m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: 52ef75616890e664ca6a6f6fbc2e8039, type: 3} m_Sprite: {fileID: 21300000, guid: 50ce219ae8c7eb04d9fa5b539144728b, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1} m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0 m_FlipX: 0
m_FlipY: 0 m_FlipY: 0
+12 -43
View File
@@ -3,13 +3,9 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class Player : MonoBehaviour { public class Player : MonoBehaviour {
public enum Mode {
FIRE, ICE, WIND,
LAST
};
Animator animator; Animator animator;
Rigidbody2D rigidBody; Rigidbody2D rigidBody;
witchAnimate witchAnimateScript;
//movement //movement
float speed; float speed;
@@ -17,10 +13,10 @@ public class Player : MonoBehaviour {
Vector2 lastDirection = new Vector2(0, -1); Vector2 lastDirection = new Vector2(0, -1);
//attacking //attacking
bool isShooting;
float lastAttack = float.NegativeInfinity; float lastAttack = float.NegativeInfinity;
const float attackDelay = 0.5f; const float attackDelay = 0.5f;
Mode mode = Mode.FIRE;
//prefabs
public GameObject firePelletPrefab; public GameObject firePelletPrefab;
public GameObject icePelletPrefab; public GameObject icePelletPrefab;
public GameObject windPelletPrefab; public GameObject windPelletPrefab;
@@ -28,6 +24,7 @@ public class Player : MonoBehaviour {
void Awake() { void Awake() {
animator = GetComponent<Animator> (); animator = GetComponent<Animator> ();
rigidBody = GetComponent<Rigidbody2D> (); rigidBody = GetComponent<Rigidbody2D> ();
witchAnimateScript = GetComponent<witchAnimate> ();
speed = 0.79f; speed = 0.79f;
} }
@@ -39,11 +36,11 @@ public class Player : MonoBehaviour {
void FixedUpdate() { void FixedUpdate() {
Move (); Move ();
Attack (); Attack ();
//SendAnimationInfo ();
} }
void HandleInput() { void HandleInput() {
//determine the input from the player //determine the input from the player
//NOTE: duplicate code
float horizontal = Input.GetAxis ("Horizontal"); float horizontal = Input.GetAxis ("Horizontal");
float vertical = Input.GetAxis ("Vertical"); float vertical = Input.GetAxis ("Vertical");
@@ -53,16 +50,6 @@ public class Player : MonoBehaviour {
if (deltaForce != Vector2.zero) { if (deltaForce != Vector2.zero) {
lastDirection = rigidBody.velocity; lastDirection = rigidBody.velocity;
} }
//calculate if shooting
isShooting = Input.GetButton ("Attack");
if (Input.GetButtonDown("Switch")) {
mode += 1;
if (mode == Mode.LAST) {
mode = 0;
}
}
} }
void Move() { void Move() {
@@ -73,18 +60,18 @@ public class Player : MonoBehaviour {
} }
void Attack() { void Attack() {
if (Time.time - lastAttack > attackDelay && isShooting) { if (Time.time - lastAttack > attackDelay && witchAnimateScript.current == witchAnimate.Deed.shoot) {
lastAttack = Time.time; lastAttack = Time.time;
GameObject pellet = null; GameObject pellet = null;
switch (mode) { switch (witchAnimateScript.el) {
case Mode.FIRE: case witchAnimate.Element.fire:
pellet = Instantiate (firePelletPrefab); pellet = Instantiate (firePelletPrefab);
break; break;
case Mode.ICE: case witchAnimate.Element.ice:
pellet = Instantiate (icePelletPrefab); pellet = Instantiate (icePelletPrefab);
break; break;
case Mode.WIND: case witchAnimate.Element.wind:
pellet = Instantiate (windPelletPrefab); pellet = Instantiate (windPelletPrefab);
break; break;
} }
@@ -96,31 +83,13 @@ public class Player : MonoBehaviour {
pellet.GetComponent<Rigidbody2D> ().AddForce (lastDirection.normalized * 2, ForceMode2D.Impulse); pellet.GetComponent<Rigidbody2D> ().AddForce (lastDirection.normalized * 2, ForceMode2D.Impulse);
} }
if (!isShooting) { if (witchAnimateScript.current != witchAnimate.Deed.shoot) {
lastAttack = float.NegativeInfinity; lastAttack = float.NegativeInfinity;
} }
} }
/*
void SendAnimationInfo() {
animator.SetFloat ("xSpeed", lastDirection.x);
animator.SetFloat ("ySpeed", lastDirection.y);
animator.SetBool ("isShooting", isShooting);
}
*/
//utilities //utilities
Vector2 GetShootingPoint() { Vector2 GetShootingPoint() {
Vector2 point = lastDirection.normalized; return lastDirection.normalized * 0.15f;
if (Mathf.Abs (point.x) == Mathf.Abs (point.y)) {
point *= 0.26f; //diagonal
} else if (Mathf.Abs (point.x) < Mathf.Abs (point.y)) {
point *= 0.23f; //vertical
} else {
point *= 0.2f; //horizontal
}
return point;
} }
} }