Commit fe1eea36 authored by Samantha Straka's avatar Samantha Straka
Browse files

changes color if puzzle right or wrong

Detected a nasty bug and cant find it
parent bfd4a465
......@@ -7,7 +7,7 @@ Material:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: wikipedia
m_Name: Wikipedia
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 4
......
This diff is collapsed.
......@@ -11,7 +11,7 @@ public class ControllerScript : MonoBehaviour
public SteamVR_Action_Boolean grab;
public SteamVR_Action_Boolean grabbed;
public SteamVR_Input_Sources handType;
private bool triggerDown;
public bool triggerDown;
private GameObject overlappedCube;
public List<String> conditions;
private int numberOfRepetitions = 0;
......@@ -40,10 +40,10 @@ public class ControllerScript : MonoBehaviour
grabbedCube.transform.SetPositionAndRotation(gameObject.transform.position,gameObject.transform.rotation);
}
......@@ -81,6 +81,7 @@ public class ControllerScript : MonoBehaviour
}
}
void OnTriggerEnter(Collider collision)
{
if(collision.gameObject.tag == "PuzzleCube")
......@@ -124,6 +125,10 @@ public class ControllerScript : MonoBehaviour
other.GetComponent<PuzzleCubeScript>().unhighLight();
if (!other.GetComponent<PuzzleCubeScript>().hasLocation()&&!triggerDown)
{
other.GetComponent<PuzzleCubeScript>().setToOriginalPosition();
}
......
......@@ -26,7 +26,7 @@ public class GameManager : MonoBehaviour
private string puzzlematerialName;
private Material posterMaterial;
bool lastCondition;
private int cubesInPuzzle=0;
int condition; //0 is no brand, 1 is poster brand, 2 is puzzle brand, 3 is audio brand
// Start is called before the first frame update
......@@ -35,9 +35,10 @@ public class GameManager : MonoBehaviour
void Start()
{
//first Condition is a random condition out of the condition List
print(conditionOrder.Count);
// print(conditionOrder.Count);
lastCondition = false;
desktopWall.SetActive(false);
......@@ -70,8 +71,47 @@ public class GameManager : MonoBehaviour
}
public bool puzzleSolvedCorrectly()
{
//yadda yadda something something durch alle cubes durchgehen und schuaen ob das geht
foreach (GameObject c in cubes)
{
c.GetComponent<PuzzleCubeScript>().atRightLocation();
}
return false;
}
public void checkHowManyCubesInPuzzle(int counter)
{
print(cubesInPuzzle);
cubesInPuzzle = cubesInPuzzle + counter;
//diese Funktion wird immer dann aufgerufen, wenn ein neuer Cube in das Puzzle gesetzt wird
print(cubesInPuzzle);
if (cubesInPuzzle == 9)
{
//alle puzzle cubes sind drin und ich sollte checken ob das puzzzle richtig gelöst wurde
if (puzzleSolvedCorrectly())
{
puzzleContainer.GetComponent<Puzzle>().setContainerMaterial(1);
}
else if (!puzzleSolvedCorrectly())
{
puzzleContainer.GetComponent<Puzzle>().setContainerMaterial(2);
}
}
else if (cubesInPuzzle < 9)
{
puzzleContainer.GetComponent<Puzzle>().setContainerMaterial(0);
}
}
//sets PosterMaterial to the desired Material m
void setPosterMaterial(string path)
{
......@@ -121,8 +161,9 @@ public class GameManager : MonoBehaviour
public void setNextCondition()
{
setPuzzleCubesToStartLocation();
cubesInPuzzle = 0;
//gets the modality of next condition
/*
* 0: poster is ad
......
......@@ -12,13 +12,25 @@ public class Puzzle : MonoBehaviour
public GameObject cube2;
private bool allCubesPlacedRight;
private int rightCounter = 0;
public Material standardPuzle;
public Material RightSolvedPuzzle;
public Material wrongSolvedPuzzle;
private Material[] mats;
private bool allCubesSortedRight = false;
private GameObject[] BlockElements;
public Puzzle(Material pic)
{
picture = pic;
}
void Start()
{
BlockElements = GameObject.FindGameObjectsWithTag("Block");
mats = BlockElements[0].GetComponent<MeshRenderer>().materials;
}
void Update()
{
......@@ -49,6 +61,43 @@ public class Puzzle : MonoBehaviour
rightCounter = 0;
return allCubesPlacedRight;
}
public void setContainerMaterial(int whichMaterial)
{
switch (whichMaterial)
{
case 0:
mats[0] = standardPuzle;
//back to normal Material
foreach (GameObject block in BlockElements)
{
block.GetComponent<MeshRenderer>().materials = mats;
}
break;
case 1:
//puzzleSolved Correct
mats[0] = RightSolvedPuzzle;
foreach (GameObject block in BlockElements)
{
block.GetComponent<MeshRenderer>().materials = mats;
}
break;
case 2:
//puzzle Solved WRONG
mats[0] = wrongSolvedPuzzle;
foreach (GameObject block in BlockElements)
{
block.GetComponent<MeshRenderer>().materials = mats;
}
break;
}
}
}
......@@ -12,6 +12,8 @@ public class PuzzleCubeScript : MonoBehaviour
private Material puzzleMaterial;
public Material highLightMaterial;
public Material locationHighlightMaterial;
private GameObject gm;
private bool triggerisdown;
private void Awake()
......@@ -19,10 +21,28 @@ public class PuzzleCubeScript : MonoBehaviour
puzzleMaterial = front.GetComponent<MeshRenderer>().materials[0];
}
public void setTriggerDown(bool isDown)
{
triggerisdown = isDown;
}
public bool hasLocation()
{
if (attachedLocation!=null)
{
return true;
}
else
return false;
}
// Start is called before the first frame update
void Start()
{
gm = GameObject.FindGameObjectWithTag("GameManager");
Cubecollider = gameObject.GetComponent<Collider>();
}
......@@ -39,7 +59,7 @@ public class PuzzleCubeScript : MonoBehaviour
//Set front of cube like index, so that it a condition can be set
private void OnCollisionEnter(Collision collision)
private void OnTriggerEnter(Collider collision)
{
if (collision.gameObject.tag == "Floor")
{
......@@ -50,7 +70,7 @@ public class PuzzleCubeScript : MonoBehaviour
//Checks if cube collides with cubeLocation
else if(collision.gameObject.tag== "PuzzleCubeLocation")
{
print("Collides with Locationm");
print(collision.gameObject.GetComponent<PuzzeCubeLocation>().isOccupied());
// highLightForLocation();
//Cube is only set to CubeLocation when it is not yet occupied, as 2 cubes on 1 location does not fit
if (!collision.gameObject.GetComponent<PuzzeCubeLocation>().isOccupied())
......@@ -61,6 +81,7 @@ public class PuzzleCubeScript : MonoBehaviour
transform.position = collision.gameObject.transform.position;
gameObject.GetComponent<Rigidbody>().useGravity = false;
gm.GetComponent<GameManager>().checkHowManyCubesInPuzzle(1);
}
}
......@@ -68,20 +89,23 @@ public class PuzzleCubeScript : MonoBehaviour
}
//When the cube is leaving the cubeLocation, the CubeLocation is no longer occupied
private void OnCollisionExit(Collision collision)
private void OnTriggerExit(Collider collision)
{
if(collision.gameObject.tag == "PuzzleCubeLocation"&& collision.gameObject.GetComponent<PuzzeCubeLocation>().isOccupied())
{
if (collision.gameObject.tag == "PuzzleCubeLocation" && collision.gameObject.GetComponent<PuzzeCubeLocation>().isOccupied())
{
attachedLocation = null;
collision.gameObject.GetComponent<PuzzeCubeLocation>().setOccupied(false);
gameObject.GetComponent<Rigidbody>().useGravity = true;
}
else if(collision.gameObject.tag == "PuzzleCubeLocation" &&! collision.gameObject.GetComponent<PuzzeCubeLocation>().isOccupied())
{
// unhighLightForLocation();
}
attachedLocation = null;
collision.gameObject.GetComponent<PuzzeCubeLocation>().setOccupied(false);
gameObject.GetComponent<Rigidbody>().useGravity = true;
gm.GetComponent<GameManager>().checkHowManyCubesInPuzzle(-1);
}
else if (collision.gameObject.tag == "PuzzleCubeLocation" && !collision.gameObject.GetComponent<PuzzeCubeLocation>().isOccupied())
{
// unhighLightForLocation();
}
}
......@@ -94,6 +118,7 @@ public class PuzzleCubeScript : MonoBehaviour
public void setToOriginalPosition()
{
transform.position = originalPosition.transform.position;
attachedLocation = null;
}
//returns the cubes index
......
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: correct
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: _ALPHAPREMULTIPLY_ON
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 10
- _GlossMapScale: 1
- _Glossiness: 0
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 3
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 0
m_Colors:
- _Color: {r: 0.22375587, g: 0.9528302, b: 0, a: 0.30588236}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
fileFormatVersion: 2
guid: 618a583a9f1075d4b9b79d146cb1dd8b
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: false
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: _ALPHAPREMULTIPLY_ON
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 10
- _GlossMapScale: 1
- _Glossiness: 0
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 3
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 0
m_Colors:
- _Color: {r: 1, g: 0.07201178, b: 0.0141509175, a: 0.22745098}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
fileFormatVersion: 2
guid: 289074c00ccee43428a21ab2b2926c8f
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:
......@@ -10,6 +10,8 @@ TagManager:
- PuzzleCube
- Floor
- Button
- GameManager
- Block
layers:
- Default
- TransparentFX
......
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