// a function to add a note to the screen public void AddNote(Transform parent) { // if there is not sticky note ref to clone then stop if (stickyNoteObj == null) { Debug.Log("no sticky note object to ref on: " + transform.name); return; } // if we have no madlibs script ref then stop if (GameObject.Find("MadLibs_Manager") == null) { Debug.Log("no reference to mad libs script found. on: " + transform.name); return; } // if we havent gotten the madlibs reference yet if (madLibsScript == null) { // get the reference to the mad libs script madLibsScript = GameObject.Find("MadLibs_Manager").GetComponent <MadLibs_Tracker>(); }// end of havent gotten mad libs ref script // make a clone ref for the new sticky GameObject stickyClone; // clone the reference sticky stickyClone = Instantiate(stickyNoteObj, stickyNoteObj.transform.position, stickyNoteObj.transform.rotation); // set the parent to the canvas stickyClone.transform.SetParent(parent); // set the scale to the appropriate size stickyClone.GetComponent <RectTransform>().localScale = new Vector3(noteSize, noteSize, noteSize); // set the position to be correct now stickyClone.GetComponent <RectTransform>().anchoredPosition = new Vector3(-200, 200, 0); // assign a new name to the sticky note stickyClone.transform.name = stickyClone.tag + "_" + nextNoteId; // set the id of the sticky note stickyClone.GetComponent <myNote>().noteId = nextNoteId; // increase the next note id number nextNoteId++; // add the note to the list of notes created in madlibs madLibsScript.AddStickys(stickyClone); }// end of add note
}// end of start // constantly detect if it is colliding with a trigger private void OnTriggerStay2D(Collider2D trig) { // if we have no madlibs script ref then stop if (GameObject.Find("MadLibs_Manager") == null) { Debug.Log("no reference to mad libs script found. on: " + transform.name); return; } // if we havent gotten the madlibs reference yet if (madlibsTracker == null) { // get the reference to the mad libs script madlibsTracker = GameObject.Find("MadLibs_Manager").GetComponent <MadLibs_Tracker>(); }// end of havent gotten mad libs ref script // if we have no ref then stop if (myNoteScript == null) { Debug.Log("No ref to 'myNote' script on: " + transform.name); return; } // if no ref to my note tracker then stop if (myNoteTracker == null) { Debug.Log("No ref to 'Note_Tracker' script on: " + transform.name); return; } //Debug.Log("Trigged with name: " + trig.gameObject.name); //Debug.Log("Trigged with tag: " + trig.gameObject.tag); // if we are done dragging the not if (myNoteScript.amDragging == false) { // if it's touching the trash if (trig.name.Contains("Trash")) { // remove this obj from the madlibs madlibsTracker.RemoveStickys(gameObject); // destroy this from the game Destroy(gameObject, 0); } // end of is touching trash } // end of done dragging // this variable is to track the number/id of the tag we are about to get int tracker = 0; // for each possible option in note tracker for tags foreach (string tag in myNoteTracker.noteCategories) { // if the triggered object has a tag in there if (trig.gameObject.tag == tag) { // assign it myNoteScript.categories.value = tracker; // assign the note tag string myNoteScript.myTagString = tag; // stop break; }// end of if obj.tag is equal to tag we are comparing else // if there is no match { //increase our tracker tracker++; } // end of no match } // end of for each tag } // end of on trigger stay 2d