Scripting changes for item and added level 1 scene #330

Merged
glencelow merged 10 commits from PlayerController into main 2023-02-02 11:20:20 +08:00
28 changed files with 5843 additions and 52 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,10 @@
Name: MD_CarRed
ID: 76808537
Type: 4
Sub Assets:
Name: CarBody
ID: 135736753
Type: 8
Name: CarWindows
ID: 139618182
Type: 8

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,22 @@
Name: MD_Prop_Large_Watermelon
ID: 70609427
Type: 4
Sub Assets:
Name: Watermelon_Unbroken
ID: 134305891
Type: 8
Name: Watermelon_Broken01
ID: 144023586
Type: 8
Name: Watermelon_Broken02
ID: 142132679
Type: 8
Name: Watermelon_Broken03
ID: 138231239
Type: 8
Name: Watermelon_Broken04
ID: 135293480
Type: 8
Name: Watermelon_Broken05
ID: 146157335
Type: 8

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,19 @@
Name: MD_Prop_Small_Egg
ID: 78383364
Type: 4
Sub Assets:
Name: Egg_Unbroken
ID: 147457317
Type: 8
Name: Egg._Broken01
ID: 134900190
Type: 8
Name: Egg._Broken02
ID: 146271645
Type: 8
Name: Egg._Broken03
ID: 135945648
Type: 8
Name: Egg._Broken04
ID: 141722646
Type: 8

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,19 @@
Name: MD_TutorialGarageProps01
ID: 75936469
Type: 4
Sub Assets:
Name: MetalShelf
ID: 141619727
Type: 8
Name: Chair01.001
ID: 139750047
Type: 8
Name: Cube.002
ID: 137072050
Type: 8
Name: Cube.003
ID: 149524108
Type: 8
Name: GarageDoor
ID: 148373587
Type: 8

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,10 @@
Name: MD_TutorialGarageProps02
ID: 79889545
Type: 4
Sub Assets:
Name: CupboardSolidBlock.001
ID: 141180771
Type: 8
Name: CupboardSinkPiece.002
ID: 141816633
Type: 8

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,10 @@
Name: MD_WashingMachine
ID: 67614549
Type: 4
Sub Assets:
Name: WashingMachine
ID: 138744683
Type: 8
Name: WashingMachineDoor
ID: 139502794
Type: 8

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,3 @@
Name: Level1Scene
ID: 96668835
Type: 5

View File

@ -8466,7 +8466,7 @@
- EID: 240
Name: ====ItemPool====
IsActive: true
NumberOfChildren: 9
NumberOfChildren: 11
Components: ~
Scripts: ~
- EID: 241
@ -8514,6 +8514,8 @@
Enabled: true
Score: 50
currCategory: 1
density: 1
dontReturn: false
- EID: 157
Name: Mesh_Meat
IsActive: true
@ -8559,6 +8561,8 @@
Enabled: true
Score: 50
currCategory: 1
density: 1
dontReturn: false
- EID: 156
Name: Mesh_Meat
IsActive: true
@ -8604,6 +8608,8 @@
Enabled: true
Score: 50
currCategory: 1
density: 1
dontReturn: false
- EID: 155
Name: Mesh_Cheese
IsActive: true
@ -8649,6 +8655,8 @@
Enabled: true
Score: 100
currCategory: 2
density: 1
dontReturn: false
- EID: 154
Name: Mesh_Cheese
IsActive: true
@ -8694,6 +8702,8 @@
Enabled: true
Score: 100
currCategory: 2
density: 1
dontReturn: false
- EID: 153
Name: Mesh_Cheese
IsActive: true
@ -8739,6 +8749,8 @@
Enabled: true
Score: 100
currCategory: 2
density: 1
dontReturn: false
- EID: 65778
Name: Mesh_Apple
IsActive: true
@ -8784,6 +8796,8 @@
Enabled: true
Score: 10
currCategory: 0
density: 1
dontReturn: false
- EID: 152
Name: Mesh_Apple
IsActive: true
@ -8829,6 +8843,8 @@
Enabled: true
Score: 10
currCategory: 0
density: 1
dontReturn: false
- EID: 151
Name: Mesh_Apple
IsActive: true
@ -8874,6 +8890,509 @@
Enabled: true
Score: 10
currCategory: 0
density: 1
dontReturn: false
- EID: 65686
Name: Watermelon
IsActive: true
NumberOfChildren: 5
Components:
Transform Component:
Translate: {x: 2.44600534, y: 0.333341181, z: 6.14019775}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 0.999979734, y: 1, z: 0.999979734}
IsActive: true
Renderable Component:
Mesh: 134305891
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Collision Tag: 1
Type: Sphere
Radius: 0.5
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts:
- Type: Breakable
Enabled: true
threshHold: 2
ignoreRaccoon: true
- Type: Item
Enabled: true
Score: 100
currCategory: 2
density: 1
dontReturn: false
- EID: 131220
Name: Piece1
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -0.0219824314, y: 2.77459621e-05, z: 0.140744686}
Rotate: {x: 0, y: 3.6088712e-09, z: 1.97286229e-16}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 144023586
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Collision Tag: 1
Type: Box
Half Extents: {x: 0.25, y: 0.25, z: 0.100000001}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0.164060935, y: 0, z: 0}
IsActive: true
Scripts:
- Type: Item
Enabled: true
Score: 10
currCategory: 1
density: 5
dontReturn: false
- EID: 131219
Name: Piece2
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0.0213363171, y: 0.0825135708, z: -0.0573720932}
Rotate: {x: 0, y: 3.6088712e-09, z: 1.97286229e-16}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 142132679
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Collision Tag: 1
Type: Box
Half Extents: {x: 0.300000012, y: 0.200000003, z: 0.200000003}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: -0.34906584}
IsActive: true
Scripts:
- Type: Item
Enabled: true
Score: 10
currCategory: 1
density: 5
dontReturn: false
- EID: 131221
Name: Piece3
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -0.0268242359, y: -0.140726641, z: -0.0336794853}
Rotate: {x: 0, y: 3.6088712e-09, z: 1.97286229e-16}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 138231239
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Collision Tag: 1
Type: Box
Half Extents: {x: 0.200000003, y: 0.0799999982, z: 0.200000003}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: -0.261799395}
IsActive: true
Scripts:
- Type: Item
Enabled: true
Score: 10
currCategory: 1
density: 5
dontReturn: false
- EID: 145
Name: Piece4
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -0.194803953, y: -0.0580093563, z: -0.00789308548}
Rotate: {x: 0, y: 3.6088712e-09, z: 1.97286229e-16}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 135293480
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Collision Tag: 1
Type: Box
Half Extents: {x: 0.200000003, y: 0.0500000007, z: 0.200000003}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: -1.04719758}
IsActive: true
Scripts:
- Type: Item
Enabled: true
Score: 10
currCategory: 1
density: 5
dontReturn: false
- EID: 196754
Name: Piece5
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -0.0839636326, y: 0.175804704, z: 0.0484313965}
Rotate: {x: 0, y: 3.6088712e-09, z: 1.97286229e-16}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 146157335
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Collision Tag: 1
Type: Box
Half Extents: {x: 0.25, y: 0.0500000007, z: 0.200000003}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0.436332315}
IsActive: true
Scripts:
- Type: Item
Enabled: true
Score: 10
currCategory: 1
density: 5
dontReturn: false
- EID: 144
Name: Egg
IsActive: true
NumberOfChildren: 4
Components:
Transform Component:
Translate: {x: 3.11708331, y: 0.333341181, z: 6.14019775}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 0.999979734, y: 1, z: 0.999979734}
IsActive: true
Renderable Component:
Mesh: 147457317
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Collision Tag: 1
Type: Sphere
Radius: 0.075000003
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts:
- Type: Breakable
Enabled: true
threshHold: 1
ignoreRaccoon: true
- Type: Item
Enabled: true
Score: 10
currCategory: 0
density: 80
dontReturn: false
- EID: 143
Name: Piece1
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0.0224030018, y: 0.0607728958, z: -0.00627422333}
Rotate: {x: 0, y: 3.6088712e-09, z: 1.97286229e-16}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 134900190
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Collision Tag: 1
Type: Box
Half Extents: {x: 0.0500000007, y: 0.0500000007, z: 0.0500000007}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0.164060935, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 142
Name: Piece2
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -0.00627422333, y: 0.0337567925, z: -0.00243234634}
Rotate: {x: 0, y: 3.6088712e-09, z: 1.97286229e-16}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 146271645
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Collision Tag: 1
Type: Box
Half Extents: {x: 0.0500000007, y: 0.0500000007, z: 0.0500000007}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: -0.34906584}
IsActive: true
Scripts: ~
- EID: 141
Name: Piece3
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -0.0166685581, y: -0.0367090404, z: 0.0114421844}
Rotate: {x: 0, y: 3.6088712e-09, z: 1.97286229e-16}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 135945648
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Collision Tag: 1
Type: Box
Half Extents: {x: 0.0500000007, y: 0.0500000007, z: 0.0500000007}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: -0.261799395}
IsActive: true
Scripts: ~
- EID: 140
Name: Piece4
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0.020128727, y: -0.0155199468, z: -0.0045747757}
Rotate: {x: 0, y: 3.6088712e-09, z: 1.97286229e-16}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 141722646
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Collision Tag: 1
Type: Box
Half Extents: {x: 0.0500000007, y: 0.0500000007, z: 0.0500000007}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: -1.04719758}
IsActive: true
Scripts: ~
- EID: 15
Name: ====ScoreZonePool====
IsActive: true
@ -8966,8 +9485,6 @@
Scripts:
- Type: GameManager
Enabled: true
itemPool: 240
zonePool: 15
winScene: 92009475
loseScene: 91685359
currGameState: 0
@ -9087,7 +9604,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0.700000048, z: 0.200000286}
Translate: {x: 0, y: 0.899999976, z: 0.200000286}
Rotate: {x: 0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
@ -9206,7 +9723,7 @@
- Type: Breakable
Enabled: true
threshHold: 0.100000001
force: 1
ignoreRaccoon: false
- EID: 196
Name: Piece1
IsActive: true
@ -9415,7 +9932,7 @@
- Type: Breakable
Enabled: true
threshHold: 0.100000001
force: 1
ignoreRaccoon: false
- EID: 65703
Name: Piece1
IsActive: true
@ -9624,7 +10141,7 @@
- Type: Breakable
Enabled: true
threshHold: 0.100000001
force: 1
ignoreRaccoon: false
- EID: 65708
Name: Piece1
IsActive: true

View File

@ -95,6 +95,9 @@ public partial class LeafAttack : BehaviourTreeNode
//Catch player when in range for long enough
//Debug.Log("Success: Caught");
player.GetScript<PlayerController>().currentState = PlayerController.RaccoonStates.CAUGHT;
if (player.GetScript<PlayerController>().stateMachine && !player.GetScript<PlayerController>().stateMachine.IsState(typeof(PlayerCaughtState)))
player.GetScript<PlayerController>().stateMachine.SetState(typeof(PlayerCaughtState));
status = BehaviourTreeNodeStatus.SUCCESS;
onExit(BehaviourTreeNodeStatus.SUCCESS);
return status;

View File

@ -7,12 +7,13 @@ using System.Xml.Linq;
public class Breakable : Script
{
public float threshHold = 1.0f;
public float force = 2.0f;
public bool ignoreRaccoon = false;
private RigidBody rb;
private Transform trans;
private bool isBreak = false;
public bool isBreak { get; set; }
private List<GameObject> itemPieces = new List<GameObject>();
private Random ran = new Random();
protected override void awake()
{
rb = GetComponent<RigidBody>();
@ -28,6 +29,8 @@ public class Breakable : Script
itemPieces.Add(pieces);
pieces.SetActive(false);
}
isBreak = false;
}
protected override void update()
@ -38,9 +41,14 @@ public class Breakable : Script
protected override void onCollisionEnter(CollisionInfo info)
{
if (ignoreRaccoon && info.GameObject.GetScript<PlayerController>())
return;
if (rb.LinearVelocity.GetSqrMagnitude() > threshHold)
{
isBreak = true;
if(GameObject.GetScript<Item>())
GameManager.Instance.totalItemCount -= 1;
}
}
protected override void onTriggerEnter(CollisionInfo info)
@ -54,12 +62,14 @@ public class Breakable : Script
{
item.SetActive(true);
item.GetComponent<Transform>().GlobalPosition = trans.LocalPosition + item.GetComponent<Transform>().LocalPosition;
if (item.GetScript<Item>())
GameManager.Instance.totalItemCount += 1;
GameObject gO = item;
gO.Parent = GameObject.Null;
}
isBreak = false;
Audio.PlaySFXOnce2D("event:/Props/impact_break");
Owner.SetActive(false);
GameObject.SetActive(false);
}
}

View File

@ -12,33 +12,65 @@ public class Item : Script
public int Score = 10;
public ItemCategory currCategory;
private RigidBody rb;
private bool once = false;
public bool returnBack { get; set; }
private Transform transform;
private bool playSound = false;
private bool caputurePos = false;
private Vector3 firstPostion;
private Collider collider;
public float density = 1.0f;
public bool dontReturn = false;
protected override void awake()
{
rb = GetComponent<RigidBody>();
transform = GetComponent<Transform>();
collider = GetComponent<Collider>();
if(collider)
collider.GetCollisionShape(0).Density = density;
returnBack = false;
}
protected override void start()
{
GameManager.Instance.totalItemCount += 1;
}
protected override void update()
{
if (returnBack && !dontReturn)
{
transform.LocalPosition = firstPostion;
returnBack = false;
}
}
protected override void onCollisionEnter(CollisionInfo info)
{
if (once)
if (!caputurePos)
{
firstPostion = transform.LocalPosition;
caputurePos = true;
}
if (playSound)
{
if(currCategory == ItemCategory.LIGHT)
Audio.PlaySFXOnce2D("event:/Props/impact_elastic");
else if (currCategory == ItemCategory.MEDIUM || currCategory == ItemCategory.HEAVY)
Audio.PlaySFXOnce2D("event:/Props/impact_hard");
once = false;
playSound = false;
}
if (info.GameObject.GetScript<Homeowner1>())
{
returnBack = true;
}
}
protected override void onCollisionExit(CollisionInfo info)
{
once = true;
playSound = true;
}
}

View File

@ -223,7 +223,6 @@ public class PickAndThrow : Script
return false;
}
return false;
}

View File

@ -31,7 +31,7 @@ public class PlayerController : Script
public Camera cam { get; set; }
public CameraArm camArm { get; set; }
private PickAndThrow pat;
private StateMachine stateMachine;
public StateMachine stateMachine;
public bool holdItem { get; set; }
public bool isAiming { get; set; }
@ -370,6 +370,13 @@ public class PlayerController : Script
if (stateMachine && !stateMachine.IsState(typeof(PlayerIdleState)))
stateMachine.SetState(typeof(PlayerIdleState));
tranform.LocalPosition = respawnPoint.GetComponent<Transform>().LocalPosition;
if (pat && pat.item.GetScript<Item>())
{
holdItem = false;
isAiming = false;
pat.item.GetScript<Item>().returnBack = true;
}
}
}

View File

@ -11,9 +11,6 @@ public class GameManager : Script
LOSE
}
public GameObject itemPool;
public GameObject zonePool;
public uint winScene = 92009475;
public uint loseScene = 91685359;
@ -26,49 +23,29 @@ public class GameManager : Script
[NonSerialized]
public float timer;
private IEnumerable<Item> listOfItems;
private IEnumerable<ScoringZone> listOfZone;
public GameObject scoreText;
public GameObject timeText;
private bool once = true;
public static GameManager Instance { get; private set; }
protected override void awake()
{
if (Instance != null && Instance != this)
RemoveScript<GameManager>();
else
Instance = this;
Audio.PlayBGMOnce2D("event:/Music/player_undetected");
Audio.PlayBGMOnce2D("event:/Ambience/roomtone_kitchen");
totalItemCount = 0;
Score = 0;
currGameState = GameState.START;
}
protected override void update()
{
Cheats();
if (once)
{
if (itemPool)
{
listOfItems = itemPool.GetScriptsInChildren<Item>();
if (listOfItems != null)
foreach (Item i in listOfItems)
totalItemCount += 1;
}
if (zonePool)
{
listOfZone = zonePool.GetScriptsInChildren<ScoringZone>();
if (listOfZone != null)
foreach (ScoringZone sz in listOfZone)
sz.gameManger = Owner.GetScript<GameManager>();
}
once = false;
}
if (currGameState == GameState.START)
{
timer -= Time.DeltaTimeF;
@ -77,7 +54,7 @@ public class GameManager : Script
if(timeText)
timeText.GetComponent<TextRenderable>().Text = $"Time Left: {timer.ToString("0.00")}";
if ((timer > 0 && totalItemCount <= 0) || Input.GetKeyDown(Input.KeyCode.F1))
if ((timer > 0 && totalItemCount < 0) || Input.GetKeyDown(Input.KeyCode.F1))
{
currGameState = GameState.WIN;
Audio.StopAllSounds();
@ -94,6 +71,12 @@ public class GameManager : Script
}
}
protected override void onDestroy()
{
if (Instance == this)
Instance = null;
}
private void Cheats()
{
if (Input.GetKeyDown(Input.KeyCode.Escape))

View File

@ -2,7 +2,6 @@
using System;
public class ScoringZone : Script
{
public GameManager gameManger { get; set; }
protected override void awake()
{
@ -10,11 +9,11 @@ public class ScoringZone : Script
protected override void onTriggerEnter(CollisionInfo info)
{
if (gameManger && info.GameObject.GetScript<Item>())
if (GameManager.Instance && info.GameObject.GetScript<Item>())
{
Audio.PlaySFXOnce2D("event:/Music/stingers/item_scored");
gameManger.Score += info.GameObject.GetScript<Item>().Score;
gameManger.totalItemCount -= 1;
GameManager.Instance.Score += info.GameObject.GetScript<Item>().Score;
GameManager.Instance.totalItemCount -= 1;
info.GameObject.SetActive(false);
}
}