Commit 207b433e authored by mmaluschnig's avatar mmaluschnig
Browse files

added 3 box colliders which tell if a key was pressed in the perfect, good, or...

added 3 box colliders which tell if a key was pressed in the perfect, good, or bad zone. also added TriggerManager script to destroy keys that were pressed in the zones.
parent 6d078784
......@@ -21,7 +21,8 @@ GameObject:
- component: {fileID: 4145066122545122}
- component: {fileID: 212894587835513782}
- component: {fileID: 114693243665785164}
m_Layer: 0
- component: {fileID: 61597912326454196}
m_Layer: 8
m_Name: Key
m_TagString: Untagged
m_Icon: {fileID: 0}
......@@ -35,12 +36,37 @@ Transform:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1765769401102260}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 5, y: 4, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalPosition: {x: 5, y: 4, z: -5}
m_LocalScale: {x: 1.6, y: 1.6, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &61597912326454196
BoxCollider2D:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1765769401102260}
m_Enabled: 1
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.8, y: 0.8}
newSize: {x: 0.8, y: 0.8}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 0.5, y: 0.02}
m_EdgeRadius: 0
--- !u!114 &114693243665785164
MonoBehaviour:
m_ObjectHideFlags: 1
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerManager : MonoBehaviour {
}
fileFormatVersion: 2
guid: 41d050973d7f949069907590e2c66c75
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -61,24 +61,24 @@ public class SpawnKeys : MonoBehaviour {
// Update is called once per frame
void Update () {
if (nextKey != null && Time.time > startTime + float.Parse(nextKey[1]))
while (nextKey != null && Time.time > startTime + float.Parse(nextKey[1]))
{
switch (nextKey[0])
{
case "left":
print("left");
//print("left");
Instantiate(arrowPrefab, new Vector3(5f, 4f, 1f), Quaternion.identity);
break;
case "right":
print("right");
//print("right");
Instantiate(arrowPrefab, new Vector3(8f, 4f, 1f), Quaternion.identity);
break;
case "up":
print("up");
//print("up");
Instantiate(arrowPrefab, new Vector3(6f, 4f, 1f), Quaternion.identity);
break;
case "down":
print("DOWN");
//print("DOWN");
Instantiate(arrowPrefab, new Vector3(7f, 4f, 1f), Quaternion.identity);
break;
default:
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TriggerManager : MonoBehaviour {
public Collider2D perfectCollider;
public Collider2D goodCollider;
public Collider2D badCollider;
//the distance between the centre of each trigger area.
public float sepparation = 1f;
public ContactFilter2D filter = new ContactFilter2D();
enum keys {left = 0, right = 3, up = 1, down = 2}
// Use this for initialization
void Start()
{
filter.SetLayerMask(LayerMask.GetMask("Key"));
}
// Update is called once per frame
void Update()
{
//Check which key the player presses
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
moveColliders((int)keys.left);
checkAllColliders();
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
moveColliders((int)keys.right);
checkAllColliders();
}
if (Input.GetKeyDown(KeyCode.UpArrow))
{
moveColliders((int)keys.up);
checkAllColliders();
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
moveColliders((int)keys.down);
checkAllColliders();
}
}
bool checkCollider(Collider2D c)
{
var results = new Collider2D[10];
if(c.OverlapCollider(filter,results) != 0){
//("YES");
Destroy(results[0].gameObject);
return true;
}
return false;
}
void moveColliders(int key){
perfectCollider.offset = new Vector2(key * sepparation, perfectCollider.offset.y);
goodCollider.offset = new Vector2(key * sepparation, goodCollider.offset.y);
badCollider.offset = new Vector2(key * sepparation, badCollider.offset.y);
}
void checkAllColliders(){
if (checkCollider(perfectCollider))
{
print("PERFECT");
}
else if (checkCollider(goodCollider))
{
print("GOOD");
}
else if(checkCollider(badCollider))
{
print("Bad");
}else{
print("That was so horrible im just gonna pretend it didnt happen");
}
}
}
fileFormatVersion: 2
guid: 82a4931dfb6f441169be246ab4d239ed
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
left 1
right 1.5
up 2.34
down 4.8
\ No newline at end of file
down 4.3
right 5.5
left 5.5
\ No newline at end of file
fileFormatVersion: 2
guid: abc7c8627cab5494da8e4bd5f24a5796
TextureImporter:
fileIDToRecycleName: {}
externalObjects: {}
serializedVersion: 7
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 53f8819c829914ae79898369b6dd7625
vertices: []
indices:
edges: []
weights: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!78 &1
TagManager:
serializedVersion: 2
tags: []
layers:
- Default
- TransparentFX
- Ignore Raycast
-
- Water
- UI
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
m_SortingLayers:
- name: Default
uniqueID: 0
locked: 0
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!78 &1
TagManager:
serializedVersion: 2
tags:
- Perfect
layers:
- Default
- TransparentFX
- Ignore Raycast
-
- Water
- UI
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
m_SortingLayers:
- name: Default
uniqueID: 0
locked: 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