Search Unity

Please Help : Trigger Issues

Discussion in 'Scripting' started by ibslixter, Sep 17, 2014.

  1. ibslixter

    ibslixter

    Joined:
    Sep 15, 2014
    Posts:
    7
    This is my script:
    using UnityEngine;
    using System.Collections;

    public class IntroDialogueText : MonoBehaviour {
    //Declar variables.
    string[] NPCTalk = new string[11];
    string[] PCTalk = new string[11];
    int myIndex = 0;
    bool myTalking = false;
    public GameObject CameraPositionPrefab;

    public GUISkin skin;

    void Start()
    {
    //Initialize values.
    NPCTalk [0] = "General : We're going to have to use that new Sargent for this job.";
    NPCTalk[1] = "Captain : Sir, with all due respect...what the hell are you thinking?";
    NPCTalk[2] = "General : I'm Sorry? Are you questioning my decision Captain?";
    NPCTalk[3] = "Captain : Yes sir I am! How can you possible send a fresh Sargent on a Commander's job? ";
    NPCTalk[4] = "General : Because he's my soldier.";
    NPCTalk[5] = "Captain : So what?!";
    NPCTalk[3] = "General : He's just a gutterspine anyway.";
    NPCTalk[4] = "Captain : Sir? How can you say that?";
    NPCTalk[5] = "General : Come now...like we don't all think that!";
    NPCTalk[6] = "Captain : I see the Emperor's bigotry has gotten to you. Beyond the point sir, why would you send the Sargent to do a Captains Job. Send me even!";
    NPCTalk [7] = "General : Look Captain...it's either the Sargent's head...or mine.";
    NPCTalk[8] = "Captain : ...He's part of YOUR navy Sir. You can't just do this to him.";
    NPCTalk [9] = "General : I can...and I will.";
    NPCTalk[10] = "Captain : ...Understood Sir.";


    PCTalk[0] = @"Next";
    PCTalk[1] = @"Next";
    PCTalk[2] = @"Next";
    PCTalk[3] = @"Next";
    PCTalk[4] = @"Next";
    PCTalk[5] = @"Next";
    PCTalk[6] = @"Next";
    PCTalk [7] = @"Next";
    PCTalk[8] = @"Next";
    PCTalk [9] = @"Next";
    PCTalk[10] = @"Next";
    }






    void OnGUI () {
    GUI.skin = skin;
    //Display the Dialog.
    if (myTalking) {
    GUI.Label (new Rect (475, 700, 800, 75), NPCTalk [myIndex]);
    if (GUI.Button (new Rect (685, 800, 350, 30), PCTalk [myIndex]))
    if (myIndex >= 10)
    myIndex = 10;
    else
    myIndex++;

    if (GUI.Button (new Rect (20, 350, 100, 30), "Skip")) {
    myTalking = false;
    {
    animation.Play ("MoveToShip");
    }
    }
    }
    }





    void OnTriggerEnter (Collider other) {

    myTalking = true;
    Debug.Log ("Object has entered");

    }



    void OnTriggerExit () {
    myTalking = false;
    }

    }







    For some reason when I have on trigger enter it wont start the dialogue menu. Can anyone help?
     
  2. NikoBusiness

    NikoBusiness

    Joined:
    May 6, 2013
    Posts:
    289
    Is the debug log appearing when you enter the trigger?
     
  3. ibslixter

    ibslixter

    Joined:
    Sep 15, 2014
    Posts:
    7
    No so I am extremely confused
     
  4. NikoBusiness

    NikoBusiness

    Joined:
    May 6, 2013
    Posts:
    289
    Then u are not entering the trigger check if the game object has rigid body atached to it
     
  5. ibslixter

    ibslixter

    Joined:
    Sep 15, 2014
    Posts:
    7
    Oh that's probably it I didn't have a rigidbody on it. Should I add it to the object going into it or the trigger collider.
     
  6. BmxGrilled

    BmxGrilled

    Joined:
    Jan 27, 2014
    Posts:
    239
    Rigidbody or characterController should both trigger a "trigger" collider. Also make sure that the isTrigger checkbox for the collider is set in the inspector to true. Hope this helps! :)
     
  7. ibslixter

    ibslixter

    Joined:
    Sep 15, 2014
    Posts:
    7
    Okay so now its showing in the log but the ui isn't showing up.
     
  8. ibslixter

    ibslixter

    Joined:
    Sep 15, 2014
    Posts:
    7
    Oh sry didn't see your post at first. Do you know why it's only displaying in the log and not showing the rect?
     
  9. BmxGrilled

    BmxGrilled

    Joined:
    Jan 27, 2014
    Posts:
    239
    do you mean the box around the gui content? change GUI.Label to GUI.Box
    Hope this helps! :)
     
  10. BmxGrilled

    BmxGrilled

    Joined:
    Jan 27, 2014
    Posts:
    239
    I think I solved it, your rects are defining X Y coordinates way off the screen, when I set these to 0 they were in view! :)
     
  11. ibslixter

    ibslixter

    Joined:
    Sep 15, 2014
    Posts:
    7
    THANK YOU SOOOO MUCH! :D
     
    BmxGrilled likes this.
  12. ibslixter

    ibslixter

    Joined:
    Sep 15, 2014
    Posts:
    7
    I have a new issue :( When I click next (aka pc talk) it still shows the new line but the first line stays for some reason.

    Edit : Fixed
     
    Last edited: Sep 17, 2014
    BmxGrilled likes this.