Commit a0915ad0 authored by Parsa Rahmaty's avatar Parsa Rahmaty

The cannonballs passing through obstacles bug fixed, The nodes not disapearing…

The cannonballs passing through obstacles bug fixed, The nodes not disapearing after being hit bug is fixed, Game loss effect added
parent add4fe8f
...@@ -109,7 +109,7 @@ Rigidbody: ...@@ -109,7 +109,7 @@ Rigidbody:
m_AngularDrag: 0.05 m_AngularDrag: 0.05
m_UseGravity: 0 m_UseGravity: 0
m_IsKinematic: 0 m_IsKinematic: 0
m_Interpolate: 0 m_Interpolate: 1
m_Constraints: 6 m_Constraints: 6
m_CollisionDetection: 2 m_CollisionDetection: 2
--- !u!114 &1317944747836374153 --- !u!114 &1317944747836374153
......
...@@ -57,7 +57,7 @@ GameObject: ...@@ -57,7 +57,7 @@ GameObject:
- component: {fileID: 5115262030957636926} - component: {fileID: 5115262030957636926}
- component: {fileID: 4362728094971556239} - component: {fileID: 4362728094971556239}
- component: {fileID: 4993034585398598532} - component: {fileID: 4993034585398598532}
- component: {fileID: 3008372001539221339} - component: {fileID: 2480487072626728824}
m_Layer: 0 m_Layer: 0
m_Name: Block m_Name: Block
m_TagString: Untagged m_TagString: Untagged
...@@ -151,7 +151,7 @@ MonoBehaviour: ...@@ -151,7 +151,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 32f386640b7207a42a2e9427aec97d2a, type: 3} m_Script: {fileID: 11500000, guid: 32f386640b7207a42a2e9427aec97d2a, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
--- !u!54 &3008372001539221339 --- !u!54 &2480487072626728824
Rigidbody: Rigidbody:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
...@@ -166,4 +166,4 @@ Rigidbody: ...@@ -166,4 +166,4 @@ Rigidbody:
m_IsKinematic: 0 m_IsKinematic: 0
m_Interpolate: 0 m_Interpolate: 0
m_Constraints: 0 m_Constraints: 0
m_CollisionDetection: 1 m_CollisionDetection: 0
...@@ -57,7 +57,7 @@ GameObject: ...@@ -57,7 +57,7 @@ GameObject:
- component: {fileID: 5115262030957636926} - component: {fileID: 5115262030957636926}
- component: {fileID: 4362728094971556239} - component: {fileID: 4362728094971556239}
- component: {fileID: 4993034585398598532} - component: {fileID: 4993034585398598532}
- component: {fileID: 877017458105610149} - component: {fileID: 7926518500587266054}
m_Layer: 0 m_Layer: 0
m_Name: Block m_Name: Block
m_TagString: Untagged m_TagString: Untagged
...@@ -151,7 +151,7 @@ MonoBehaviour: ...@@ -151,7 +151,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 32f386640b7207a42a2e9427aec97d2a, type: 3} m_Script: {fileID: 11500000, guid: 32f386640b7207a42a2e9427aec97d2a, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
--- !u!54 &877017458105610149 --- !u!54 &7926518500587266054
Rigidbody: Rigidbody:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
......
...@@ -57,7 +57,7 @@ GameObject: ...@@ -57,7 +57,7 @@ GameObject:
- component: {fileID: 5115262030957636926} - component: {fileID: 5115262030957636926}
- component: {fileID: 4362728094971556239} - component: {fileID: 4362728094971556239}
- component: {fileID: 4993034585398598532} - component: {fileID: 4993034585398598532}
- component: {fileID: 2583980369886953638} - component: {fileID: 7206499325325071053}
m_Layer: 0 m_Layer: 0
m_Name: Block m_Name: Block
m_TagString: Untagged m_TagString: Untagged
...@@ -151,7 +151,7 @@ MonoBehaviour: ...@@ -151,7 +151,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 32f386640b7207a42a2e9427aec97d2a, type: 3} m_Script: {fileID: 11500000, guid: 32f386640b7207a42a2e9427aec97d2a, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
--- !u!54 &2583980369886953638 --- !u!54 &7206499325325071053
Rigidbody: Rigidbody:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
......
...@@ -132,6 +132,7 @@ GameObject: ...@@ -132,6 +132,7 @@ GameObject:
- component: {fileID: 58095959} - component: {fileID: 58095959}
- component: {fileID: 58095962} - component: {fileID: 58095962}
- component: {fileID: 58095961} - component: {fileID: 58095961}
- component: {fileID: 58095960}
m_Layer: 10 m_Layer: 10
m_Name: Cylinder m_Name: Cylinder
m_TagString: Untagged m_TagString: Untagged
...@@ -153,6 +154,19 @@ Transform: ...@@ -153,6 +154,19 @@ Transform:
m_Father: {fileID: 768744113} m_Father: {fileID: 768744113}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!65 &58095960
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 58095958}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1.0000001, y: 2, z: 1.0000002}
m_Center: {x: 0.000000059604645, y: 0, z: -0.00000008940697}
--- !u!23 &58095961 --- !u!23 &58095961
MeshRenderer: MeshRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
......
...@@ -6,7 +6,7 @@ public class CannonControls : MonoBehaviour ...@@ -6,7 +6,7 @@ public class CannonControls : MonoBehaviour
{ {
[SerializeField] private GameObject projectile = null; [SerializeField] private GameObject projectile = null;
[SerializeField] private float shootingDelay = 0.2f; [SerializeField] private float shootingDelay = 0.2f;
[SerializeField] private Collider[] cannonColliders; [SerializeField] private Collider[] cannonColliders = null;
private float delay; private float delay;
private float timeLeftToShoot = 0f; // the amount of time passed since last shot private float timeLeftToShoot = 0f; // the amount of time passed since last shot
private bool isOn = true; private bool isOn = true;
...@@ -17,6 +17,8 @@ public class CannonControls : MonoBehaviour ...@@ -17,6 +17,8 @@ public class CannonControls : MonoBehaviour
GameEvents.instance.onNextLevelEvent += PauseControl; GameEvents.instance.onNextLevelEvent += PauseControl;
GameEvents.instance.onGameLostEvent += TurnOffControls; GameEvents.instance.onGameLostEvent += TurnOffControls;
GameEvents.instance.onGameRestartEvent += TurnOnControls; GameEvents.instance.onGameRestartEvent += TurnOnControls;
GameEvents.instance.onGameLostEvent += TurnOffColliderTrigger;
GameEvents.instance.onGameRestartEvent += TurnOnColliderTrigger;
} }
void Update() void Update()
...@@ -58,6 +60,18 @@ public class CannonControls : MonoBehaviour ...@@ -58,6 +60,18 @@ public class CannonControls : MonoBehaviour
isOn = false; isOn = false;
} }
private void TurnOnColliderTrigger()
{
foreach (Collider collider in cannonColliders)
collider.isTrigger = true;
}
private void TurnOffColliderTrigger()
{
foreach (Collider collider in cannonColliders)
collider.isTrigger = false;
}
void PauseControl() void PauseControl()
{ {
StartCoroutine("StopControls"); StartCoroutine("StopControls");
......
...@@ -14,9 +14,7 @@ public class GameManager : MonoBehaviour ...@@ -14,9 +14,7 @@ public class GameManager : MonoBehaviour
private void Start() private void Start()
{ {
//GameEvents.instance.onGameLostEvent += StopGame;
GameEvents.instance.onNextLevelEvent += AddWinScore; GameEvents.instance.onNextLevelEvent += AddWinScore;
//GameEvents.instance.onNextLevelEvent += ShortPause;
} }
private void StopGame() private void StopGame()
......
...@@ -4,43 +4,50 @@ using UnityEngine; ...@@ -4,43 +4,50 @@ using UnityEngine;
public class NodeHolder : MonoBehaviour public class NodeHolder : MonoBehaviour
{ {
public LinkedList<DestroyableObject> nodes { get; private set; } public DestroyableObject[] nodes { get; private set; }
[SerializeField] private DestroyableObject stackNodeObject = null; [SerializeField] private DestroyableObject stackNodeObject = null;
private int index;
public void MakeNodes(int numberOfNodes) public void MakeNodes(int numberOfNodes)
{ {
if(nodes == null) if(nodes == null)
nodes = new LinkedList<DestroyableObject>(); nodes = new DestroyableObject[numberOfNodes];
for (int i = 0; i < nodes.Count; i++) for (int i = 0; i < nodes.Length; i++)
{ {
nodes.First.Value.Kill(); nodes[i]?.Kill();
nodes.RemoveFirst();
} }
// The linked list is now empty nodes = new DestroyableObject[numberOfNodes];
// The list is now empty
float nodeHeight = stackNodeObject.gameObject.GetComponent<StackNode>().GetNodeHeight(); float nodeHeight = stackNodeObject.gameObject.GetComponent<StackNode>().GetNodeHeight();
for(int i = 0; i < numberOfNodes; i++) for(int i = 0; i < numberOfNodes; i++)
{ {
DestroyableObject node = Instantiate(stackNodeObject); DestroyableObject node = Instantiate(stackNodeObject);
node.transform.parent = gameObject.transform; node.transform.parent = gameObject.transform;
//if(nodeHeight == 0f) nodeHeight = node.gameObject.GetComponent<StackNode>()
node.transform.localPosition = new Vector3(0f, i * nodeHeight, 0f); node.transform.localPosition = new Vector3(0f, i * nodeHeight, 0f);
nodes.AddLast(node); nodes[i] = node;
} }
index = 0;
} }
public void RemoveBottomNode() public void RemoveBottomNode()
{ {
if (nodes.Count != 0) if (nodes.Length != 0)
{ {
DestroyableObject node = nodes.First.Value; Destroy(nodes[index].gameObject);
nodes.RemoveFirst(); nodes[index] = null;
Destroy(node.gameObject); index++;
} }
} }
public DestroyableObject GetBottomNode() public DestroyableObject GetBottomNode()
{ {
return nodes.First.Value; return nodes[index];
}
public bool AreNodesFinished()
{
return (index == nodes.Length);
} }
} }
...@@ -4,12 +4,28 @@ using UnityEngine; ...@@ -4,12 +4,28 @@ using UnityEngine;
public class Obstacle : MonoBehaviour public class Obstacle : MonoBehaviour
{ {
private void Start()
{
GameEvents.instance.onGameLostEvent += TurnOnGravity;
}
private void OnTriggerEnter(Collider other) private void OnTriggerEnter(Collider other)
{ {
if(other.gameObject.tag.Equals("Cannonball")) if (other.gameObject.tag.Equals("Cannonball"))
{ {
if (other.gameObject.GetComponent<Cannonball>().hasHitObstacle == false)
other.gameObject.GetComponent<Movable>().UnoReverseCard(); other.gameObject.GetComponent<Movable>().UnoReverseCard();
other.gameObject.GetComponent<Cannonball>().HitObstacle(); other.gameObject.GetComponent<Cannonball>().HitObstacle();
} }
} }
private void TurnOnGravity()
{
GetComponentInChildren<Collider>().isTrigger = false;
}
private void OnDestroy()
{
GameEvents.instance.onGameLostEvent -= TurnOnGravity;
}
} }
...@@ -4,5 +4,8 @@ ...@@ -4,5 +4,8 @@
EditorBuildSettings: EditorBuildSettings:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
serializedVersion: 2 serializedVersion: 2
m_Scenes: [] m_Scenes:
- enabled: 1
path: Assets/Scenes/SampleScene.unity
guid: 9fc0d4010bbf28b4594072e72b8655ab
m_configObjects: {} m_configObjects: {}
...@@ -35,6 +35,9 @@ GraphicsSettings: ...@@ -35,6 +35,9 @@ GraphicsSettings:
- {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: [] m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0} type: 0}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment