Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by cakegamer · Mar 05, 2014 at 10:00 PM · c#javascriptgameobject

press e to speek

I have this old NPC chat box system that was given to me. I do not know where to edit this to remove the chat box and just have a button floating above the NPC’s head. I would like the button to load a new level when clicked.

her the npc chat box system script

     using UnityEngine;
     using System.Collections;
     
     //Put this script on your NPC
     
     public class NPCTalkBox : MonoBehaviour
     {
         public string npcTextMessage = "Hello, I'm an NPC"; //Message to show on the screen
         public Rect popupBox = new Rect(0.25f, 0.75f, 0.5f, 0.1f); //This is the size of your popup box in screen size
         public Rect messageBox = new Rect(0.1f, 0.7f, 0.8f, 0.2f); //This is the size of your message box in screen size
         public Transform player; //The player that we're checking the distance from
         public float minDistance = 1f; //How far away we have to be in order to show the message
         
         private bool inRange = false; //Controls showing the 'ready to talk' message
         private bool showText = false; //Controls showing the NPC message
         
         void Start()
         {
             //If you've forgotten to setup the player in the Inspector.. then I'm going to send you an angry message
             if(player == null)
             {
                 Debug.LogError("Variable 'player' not set up on "+gameObject.name+". Disabling the associated script.");
                 this.enabled = false;
             }
         }
         
         void Update()
         {
             if(Vector3.Distance(transform.position, player.position) <= minDistance) //Are we close enough?
             {
                 //Toggle showing the "press X to talk" message
                 inRange = true;
                 
                 //Toggle showing the text every time we press Fire1
                 if(Input.GetButtonDown("Fire1"))
                 {
                     showText = !showText; 
                 }
             }
             else
             {
                 //Hide the text if we walk out of range
                 inRange = false;
                 showText = false;
             }
         }
         
         void OnGUI()
         {
             if(inRange && !showText)
             {
                 GUI.Box(new Rect(Screen.width*popupBox.x, Screen.height*popupBox.y, Screen.width*popupBox.width, Screen.height*popupBox.height), "Press to talk to "+gameObject.name+".");
             }
             
             if(showText)
             {
                 GUI.Box(new Rect(Screen.width*messageBox.x, Screen.height*messageBox.y, Screen.width*messageBox.width, Screen.height*messageBox.height), npcTextMessage);
             }
         }
     }
 

ples help

Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Graham-Dunnett ♦♦ · Mar 05, 2014 at 10:05 PM 0
Share

(I've published to the site - I suspect the OP will reword the question)

avatar image thornekey · Mar 05, 2014 at 10:09 PM 0
Share

maybe, ins$$anonymous$$d of checking if your in range, then checking if you pressed E, it should be check to see if in a collider(set as trigger) (this will be your range checker) AND (so its a "&&" )if youve pressed E, then do it.

Also im not sure if GUI can go above peoples heads as its restricted to a 2D space and only on your view port. Perhaps use 3D Text and edit the mesh in script?

just a thought

avatar image cakegamer · Mar 06, 2014 at 06:18 PM 0
Share

Could you tell me what to edit and where it should go because I have some questions? If we just had to press the ‘E’ key then I would have to rewrite the script to say “press e to interact”. Of course, I can definitely do that, but my biggest problem is that I am scared about the whole range thing. I don’t want people to be able to keep pressing the button to go to the next level.

avatar image cakegamer · Mar 06, 2014 at 06:32 PM 0
Share

i am im going be editing some of my post tonite wan i get home and have my dragon softwer on hand but why did you get rid of my dislexsya point i sead that so ppl dont think im perpisly doing this

avatar image Dblfstr · Mar 06, 2014 at 06:44 PM 0
Share

“i have this old npc chat box system that wus given by my frend who is no longer my frnd eney wahy i dont to edit this wer i get rid of the chat box in genral and gust have the floting buten on top of ther head and wan you click it it will tp you no a new level.”

I have this old NPC chat box system that was given to me. I do not know where to edit this to remove the chat box and just have a button floating above the NPC’s head. I would like the button to load a new level when clicked.

“wall cold you tall me wer and wut i wold put in to do that? but this duse bring up some qrechon if we wold have to gust do the e key then i wold have to rewrite the script to say pret e to interact of cors i can defintly do but my bigis problum im scerd about is the hole range thing in wich i dont wont ppl to gust keep presing e to tp to the next level”

Could you tell me what to edit and where it should go because I have some questions? If we just had to press the ‘E’ key then I would have to rewrite the script to say “press e to interact”. Of course, I can definitely do that, but my biggest problem is that I am scared about the whole range thing. I don’t want people to be able to keep pressing the button to go to the next level.

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

It is not possible to invoke an expression of type 'UnityEngine.GameObject'? 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Refering to gameobject script is attached to 1 Answer

Problem with PlayerHealth and renderer 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges