Commit 1fc4685b authored by astatham's avatar astatham
Browse files

Targets can fall through back wall, no longer counts as a hit if a pie lands...

Targets can fall through back wall, no longer counts as a hit if a pie lands on an already-hit target
parent 0551d2f8
......@@ -124,9 +124,9 @@ SpriteRenderer:
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_SortingLayerID: -1966733235
m_SortingLayer: 2
m_SortingOrder: 4
m_Sprite: {fileID: 21300000, guid: 0b8ef5caf917b91458ec8edc45766835, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
......
......@@ -326,7 +326,7 @@ GameObject:
- component: {fileID: 234002385}
- component: {fileID: 234002384}
- component: {fileID: 234002387}
m_Layer: 0
m_Layer: 10
m_Name: RightWall
m_TagString: Untagged
m_Icon: {fileID: 0}
......@@ -644,6 +644,26 @@ Prefab:
propertyPath: m_Name
value: target (1)
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: m_Offset.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: m_SpriteTilingProperty.oldSize.x
value: 1.25
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: m_SpriteTilingProperty.oldSize.y
value: 2.51
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: m_Size.x
value: 0.1
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: m_Size.y
value: 0.1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: ff3bdd84db8dba5468da0ea66e4bac21, type: 2}
m_IsPrefabAsset: 0
......@@ -1020,7 +1040,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1a8f5a68b95cfc0429f6f5a25d89152e, type: 3}
m_Name:
m_EditorClassIdentifier:
posChangeSpeed: 2
maxPos: 8
minPos: 6
yPos: 3.58
......@@ -2181,7 +2200,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1a8f5a68b95cfc0429f6f5a25d89152e, type: 3}
m_Name:
m_EditorClassIdentifier:
posChangeSpeed: 2
maxPos: 8
minPos: 6
yPos: -3.3
......@@ -2661,7 +2679,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1a8f5a68b95cfc0429f6f5a25d89152e, type: 3}
m_Name:
m_EditorClassIdentifier:
posChangeSpeed: 2
maxPos: 8
minPos: 6
yPos: 0.14
......
......@@ -4,7 +4,7 @@ using UnityEngine;
public class MovingTarget : MonoBehaviour {
public float posChangeSpeed, maxPos, minPos, yPos;
public float maxPos, minPos, yPos;
public static float currentPos = 8f;
public static float previousPos = 8f;
......@@ -35,27 +35,27 @@ public class MovingTarget : MonoBehaviour {
{
gameObject.transform.position = new Vector3(currentPos, yPos, 0);
previousPos = currentPos;
currentPos += (posChangeSpeed * Time.deltaTime);
currentPos += (PieManager.posChangeSpeed+2 * Time.deltaTime);
}
else if (currentPos <= maxPos && currentPos > minPos && currentPos < previousPos)
{
gameObject.transform.position = new Vector3(currentPos, yPos, 0);
previousPos = currentPos;
currentPos -= (posChangeSpeed * Time.deltaTime);
currentPos -= (PieManager.posChangeSpeed + 2 * Time.deltaTime);
}
else if (currentPos > previousPos)
{
gameObject.transform.position = new Vector3(currentPos, yPos, 0);
previousPos = currentPos;
currentPos -= (posChangeSpeed * Time.deltaTime);
currentPos -= (PieManager.posChangeSpeed + 2 * Time.deltaTime);
}
else if (currentPos < previousPos)
{
gameObject.transform.position = new Vector3(currentPos, yPos, 0);
previousPos = currentPos;
currentPos += (posChangeSpeed * Time.deltaTime);
currentPos += (PieManager.posChangeSpeed + 2 * Time.deltaTime);
}
}
......
......@@ -9,6 +9,10 @@ public class Pie : MonoBehaviour {
public static float forceAmount;
public float minForce = 4f;
public float maxForce = 8f;
bool collided = false;
float offsetX, offsetY;
Collider2D impact;
public static Vector3 relativePosition;
// Use this for initialization
void Start () {
......@@ -21,12 +25,19 @@ public class Pie : MonoBehaviour {
PieManager.start = false;
if (!collision.GetComponent<PieTarget>())
{
//gameObject.GetComponent<Transform>().SetParent(GetComponent<Collider2D>().transform);
gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(0, 0);
gameObject.GetComponent<Rigidbody2D>().gravityScale = 0;
Destroy(gameObject.GetComponent<Collider2D>());
} else if (collision.tag != "TargetHit")
{
//Destroy(gameObject);
gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(0, 0);
gameObject.GetComponent<Rigidbody2D>().gravityScale = 0;
impact = collision.gameObject.GetComponent<Collider2D>();
this.collided = true;
relativePosition = impact.transform.position - gameObject.transform.position;
//print(relative);
Destroy(gameObject.GetComponent<Collider2D>());
Destroy(gameObject);
}
}
......@@ -39,6 +50,12 @@ public class Pie : MonoBehaviour {
float angle = Mathf.Atan2(moveDirection.y, moveDirection.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
}
if (this.collided)
{
//this.impact = transform.InverseTransformPoint(impact);
//gameObject.transform.position = impact.transform.position-relativePosition;
//gameObject.transform.rotation = impact.transform.rotation;
}
}
void Launch(){
......
......@@ -12,6 +12,7 @@ public class PieManager : MonoBehaviour {
public static int numTargets;
public Text exitText;
public Text exitTimer;
public static int posChangeSpeed = 0;
private bool gameOver;
private float exitTime;
......@@ -19,6 +20,10 @@ public class PieManager : MonoBehaviour {
private void Update()
{
if(pieCount == 0 || numTargets == 0){
if (numTargets == 0)
{
exitText.text = "All targets hit!";
}
if (!gameOver) {
gameOver = true;
exitTime = Time.time + 5;
......
......@@ -3,8 +3,7 @@ using System.Collections.Generic;
using UnityEngine;
public class PieTarget : MonoBehaviour {
private float timeStart;
void Start()
{
......@@ -24,23 +23,18 @@ public class PieTarget : MonoBehaviour {
PieManager.score += 100;
}
PieManager.numTargets--;
if (gameObject.tag != "TargetHit")
{
PieManager.numTargets--;
}
gameObject.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic;
//gameObject.GetComponent<Collider2D>().isTrigger = true;
float force = Pie.getForceAmount();
gameObject.GetComponent<Rigidbody2D>().AddForce(transform.right * force);
//Destroy(gameObject);
gameObject.tag = "TargetHit";
print(PieManager.numTargets);
}
}
private void OnCollisionStay2D(Collision2D collision)
{
timeStart += Time.deltaTime;
if (timeStart > 100)
{
Destroy(gameObject);
}
}
}
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