From 2be31208a5e611af9e468362d3ddd8477d44fbc0 Mon Sep 17 00:00:00 2001 From: jordanci Date: Sun, 31 Jan 2021 15:57:05 +1100 Subject: [PATCH 1/2] baby check working --- Assets/Baby.prefab | 3 +- Assets/ParentBehaviour.cs | 87 +++++++++++++++++++-------- Assets/Scenes/MainGameplayScene.unity | 4 +- Assets/Scripts/spawner.cs | 2 +- ProjectSettings/TagManager.asset | 4 +- 5 files changed, 70 insertions(+), 30 deletions(-) diff --git a/Assets/Baby.prefab b/Assets/Baby.prefab index a4714e3..f09fb74 100644 --- a/Assets/Baby.prefab +++ b/Assets/Baby.prefab @@ -422,7 +422,7 @@ GameObject: - component: {fileID: 933390416532010} m_Layer: 0 m_Name: Baby - m_TagString: Untagged + m_TagString: Child m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -539,6 +539,7 @@ MonoBehaviour: faceObj: {fileID: 1577162025261597670} topObj: {fileID: 6588930193113420027} bottomObj: {fileID: 4834944236669872262} + m_RandomizeOnAwake: 0 --- !u!114 &933390416532010 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/ParentBehaviour.cs b/Assets/ParentBehaviour.cs index 839fffc..2c78736 100644 --- a/Assets/ParentBehaviour.cs +++ b/Assets/ParentBehaviour.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.UI; public class ParentBehaviour : MonoBehaviour { @@ -31,8 +32,11 @@ public class ParentBehaviour : MonoBehaviour private void Start() { - parentBodyObj.GetComponent().material.mainTexture = parentBases[Random.Range(0, parentBases.Length)]; - parentFaceObj.GetComponent().material.mainTexture = parentFaceNeutral; + Texture _displayGraphic = parentBases[Random.Range(0, parentBases.Length)]; + parentBodyObj.GetComponent().sprite = Sprite.Create((Texture2D)_displayGraphic, new Rect(0.0f, 0.0f, _displayGraphic.width, _displayGraphic.height), new Vector2(0.5f, 0.5f), 100.0f); + + _displayGraphic = parentFaceNeutral; + parentFaceObj.GetComponent().sprite = Sprite.Create((Texture2D)_displayGraphic, new Rect(0.0f, 0.0f, _displayGraphic.width, _displayGraphic.height), new Vector2(0.5f, 0.5f), 100.0f); } [ContextMenu("Get Random Child")] @@ -45,13 +49,10 @@ public class ParentBehaviour : MonoBehaviour child = babySpawner.transform.GetChild(_childIndex).gameObject; - if (otherParent.child != null) + if (!ReferenceEquals(child, otherParent.child) || otherParent.child == null) { - if (child != otherParent.child) - { - //this prevents both parents asking for the same child - _validChild = true; - } + //this prevents both parents asking for the same child + _validChild = true; } } Randomizer _childRandomizer = child.GetComponent(); @@ -67,6 +68,8 @@ public class ParentBehaviour : MonoBehaviour order.Insert(Random.Range(0, order.Count), "eye"); order.Insert(Random.Range(0, order.Count), "top"); order.Insert(Random.Range(0, order.Count), "bottom"); + + GiveFirstDetail(); } public bool CheckChild(GameObject _child) @@ -83,36 +86,43 @@ public class ParentBehaviour : MonoBehaviour public Texture GiveDetails(GameObject _child) { + + for (int i = 0; i < order.Count; i++) { switch (order[i]){ case "base": - if (child.GetComponent().baseObj.GetComponent().material.mainTexture != baseVis) + if (_child.GetComponent().baseObj.GetComponent().material.mainTexture.name != baseVis.name) { + print("returning baseVis"); return baseVis; } break; case "hat": - if (child.GetComponent().hatObj.GetComponent().material.mainTexture != hatVis) + if (_child.GetComponent().hatObj.GetComponent().material.mainTexture.name != hatVis.name) { + print("returning hatVis"); return hatVis; } break; case "eye": - if (child.GetComponent().eyeObj.GetComponent().material.mainTexture != eyeVis) + if (_child.GetComponent().eyeObj.GetComponent().material.mainTexture.name != eyeVis.name) { + print("returning eyeVis"); return eyeVis; } break; case "top": - if (child.GetComponent().topObj.GetComponent().material.mainTexture != topVis) + if (_child.GetComponent().topObj.GetComponent().material.mainTexture.name != topVis.name) { + print("returning topVis"); return topVis; } break; case "bottom": - if (child.GetComponent().bottomObj.GetComponent().material.mainTexture != bottomVis) + if (_child.GetComponent().bottomObj.GetComponent().material.mainTexture.name != bottomVis.name) { + print("returning bottomVis"); return bottomVis; } break; @@ -123,21 +133,50 @@ public class ParentBehaviour : MonoBehaviour return null; } - private void OnTriggerEnter(Collider other) + public void GiveFirstDetail() { - if (other.gameObject.tag == "child") + Texture _displayGraphic; + switch (order[0]) { - if (CheckChild(other.gameObject)) - { - //this is the correct child - } - else + case "base": + _displayGraphic = baseVis; + break; + case "hat": + _displayGraphic = hatVis; + break; + case "eye": + _displayGraphic = eyeVis; + break; + case "top": + _displayGraphic = topVis; + break; + case "bottom": + _displayGraphic = bottomVis; + break; + default: + _displayGraphic = null; + break; + } + parentDialougeObj.GetComponent().sprite = Sprite.Create((Texture2D)_displayGraphic, new Rect(0.0f, 0.0f, _displayGraphic.width, _displayGraphic.height), new Vector2(0.5f, 0.5f), 100.0f); + } + + private void OnCollisionEnter(Collision collision) + { + if (child != null) + { + if (collision.collider.gameObject.tag == "Child") { - Texture _displayGraphic = GiveDetails(other.gameObject); - //display the display graphic - parentDialougeObj.GetComponent().material.mainTexture = _displayGraphic; + if (CheckChild(collision.collider.gameObject)) + { + //this is the correct child + } + else + { + Texture _displayGraphic = GiveDetails(collision.collider.gameObject); + //display the display graphic + parentDialougeObj.GetComponent().sprite = Sprite.Create((Texture2D)_displayGraphic, new Rect(0.0f, 0.0f, _displayGraphic.width, _displayGraphic.height), new Vector2(0.5f, 0.5f), 100.0f); + } } } } - } diff --git a/Assets/Scenes/MainGameplayScene.unity b/Assets/Scenes/MainGameplayScene.unity index fc3f45b..66a508e 100644 --- a/Assets/Scenes/MainGameplayScene.unity +++ b/Assets/Scenes/MainGameplayScene.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cadc7b5a70415603f8b6c36fa4e9da5e781d7c951d222660b161fa8dfc4d80db -size 718598 +oid sha256:5d191edf558d0b55b1ae30476a4683fb7472518babdcee2b55a20cd972372616 +size 719035 diff --git a/Assets/Scripts/spawner.cs b/Assets/Scripts/spawner.cs index a1c5c28..59886c4 100644 --- a/Assets/Scripts/spawner.cs +++ b/Assets/Scripts/spawner.cs @@ -24,7 +24,7 @@ public class spawner : MonoBehaviour { Vector3 _spawnPoint = RandomPointInBounds(spawnVolumes[Random.Range(0, spawnVolumes.Length)].bounds); - _spawnPoint.y = 1.5f; + _spawnPoint.y = 2.5f; var _newChild = Instantiate(childPrefab, _spawnPoint, Quaternion.identity); _newChild.transform.parent = this.transform; diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 8d0fed2..690c0a7 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9234e7ac4d5cd6d4d21b26fbbb2530b754e87a147df38e852bf774ccf5179b44 -size 421 +oid sha256:9bf979d6c314282e8e3171a0c8f54c6c0a192f5ac641d3b5b40106b81127c3e3 +size 385 From 6db9d3304310da61af95814b2e7922867100e6bc Mon Sep 17 00:00:00 2001 From: jordanci Date: Sun, 31 Jan 2021 15:59:32 +1100 Subject: [PATCH 2/2] jeff pls yeet --- Assets/ParentBehaviour.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Assets/ParentBehaviour.cs b/Assets/ParentBehaviour.cs index 2c78736..d7f4837 100644 --- a/Assets/ParentBehaviour.cs +++ b/Assets/ParentBehaviour.cs @@ -168,6 +168,7 @@ public class ParentBehaviour : MonoBehaviour { if (CheckChild(collision.collider.gameObject)) { + print("correct child"); //this is the correct child } else @@ -175,6 +176,9 @@ public class ParentBehaviour : MonoBehaviour Texture _displayGraphic = GiveDetails(collision.collider.gameObject); //display the display graphic parentDialougeObj.GetComponent().sprite = Sprite.Create((Texture2D)_displayGraphic, new Rect(0.0f, 0.0f, _displayGraphic.width, _displayGraphic.height), new Vector2(0.5f, 0.5f), 100.0f); + + //yeet child back to centre of room + //child = collision.collider.gameObject } } }