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 /
This question was closed Dec 29, 2018 at 05:52 PM by Bunny83 for the following reason:

Question is off-topic or not relevant

avatar image
-3
Question by kbeaud · Nov 23, 2012 at 09:58 PM · c#javascript

Talking Code

1) I need a code so when my character gets within like 3 or something a bar at the bottom will appear, that says, "To talk to (person's name) press T" (For this one please make it so in the inspector I can change the name of the character, so I can use the same script multiple times. If you can that is.)

2) I need another code that when you press "T" it initializes the talk. I don't care whether I can edit in the inspector or not.

3) I would like also to make it a conversation, but you don't actually get a choice of what to say... So it may for example go like this: Your Character: Hi Person you talk to: What do you want? and so on...

4) If possible can you make it all one code?

I thank anyone who helps. I know my rating is bad, but that's because I happen to be impatient and post the same question multiple times. I have stop this though, unless I wait like two weeks without a useful answer.

*By the way I don't care what kinda script you use.

Comment
Comments Locked · Show 6
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 Kiloblargh · Nov 23, 2012 at 10:14 PM 5
Share

No, you have a bad rating because this site is for getting help with your own coding, it's not a charity script kitchen for the clueless.

avatar image IT_Criminal · Nov 24, 2012 at 08:57 AM 0
Share

^ awfuly true

avatar image fifty6 · Nov 24, 2012 at 08:18 PM 0
Share

What is wrong with him looking for some help? This is Unity Answers not UnityScriptingAnswersOnly. I think you should keep bs comments like this to yourself and quit wasting your time giving negative feedback to those who are tyring to do the same thing you are. Create Games.

avatar image IT_Criminal · Nov 25, 2012 at 08:18 AM 2
Share

are u kidding me ? ... i bet he didn't even bother to read a coding tutorial...

avatar image kbeaud · Nov 25, 2012 at 02:16 PM 1
Share

I have actually... And I understand very basics of C# coding. You know I'm sorry if this annoys you, but live with it. Everyone here is trying to do the same thing... $$anonymous$$ake a game. $$anonymous$$y game I'm making is probably a lttle too much for me, but I'm gonna try it anyway.

Show more comments

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by greatestprez · Nov 24, 2012 at 05:57 PM

Here ya go! (apply it to the character that you want to talk & makes sure you player has the tag "Player" )

 using UnityEngine;
 using System.Collections;
 
 public class SimpleTalk : MonoBehaviour {
      
     public bool loop;
     public bool lookAt; 
     //public GUIText text;  
     //public Transform target;
     public string[] conversation;
     public float damping = 3.5f; 
     
     private int convoIndex = 0;
     private string currentTalk = ""; 
     private bool playerIn = false;  
     // Use this for initialization
     //private GUIText pGUI;  
     
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
         //LookAtIgnoreHeight(target);
     }
     
 //    void OnTriggerEnter(Collider col) {
 //    
 //        if (col.gameObject.tag == "Player") {
 //            
 //            //col.gameObject.GetComponent<MouseLook>().enabled = false; 
 //            //col.transform.FindChild("Main Camera").GetComponent<MouseLook>().enabled = false; 
 //            
 //            
 //        }
 //    }
     
     void OnTriggerStay(Collider col) {
         
         if (lookAt) {
             smoothLookAtIgnoreHeight(col.transform); 
         }
         
         bool pressed = false;
         
         if (col.gameObject.tag == "Player") {
         
             currentTalk = conversation[convoIndex]; 
             
             if (Input.GetKeyDown("t")) {
                 pressed = true; 
             }     
             
             if (Input.GetKeyUp("t")) {
                 if (pressed = true) {
                     convoIndex++; 
                     pressed = false; 
                     if (convoIndex >= conversation.Length) {
                         if (loop) convoIndex = 0; 
                         else convoIndex = conversation.Length - 1; 
                     }
                 }
             }
         }
     }
     
     void OnTriggerExit(Collider col) {
     
         if (col.gameObject.tag == "Player") {
             
             //col.gameObject.GetComponent<MouseLook>().enabled = true; 
             //col.transform.FindChild("Main Camera").GetComponent<MouseLook>().enabled = true; 
         
             currentTalk = ""; 
             playerIn = false; 
         }
     }
     
     void OnGUI() {
             
             /**if (!pGUI)*/ GUI.Label(new Rect(0,0,Screen.width,20), currentTalk); 
             //else pGUI.text = currentTalk; 
     }
     
     void LookAtIgnoreHeight (Transform target) {
 
         Vector3 lookAtPos = target.position;
         //Set y of LookAt target to be my height.
         lookAtPos.y = transform.position.y;
            transform.LookAt(lookAtPos);
     }
     
     void smoothLookAtIgnoreHeight(Transform target) {
             Vector3 targetPos = target.position;
 
             targetPos.y = transform.position.y; 
             
             Quaternion rotation = Quaternion.LookRotation(targetPos - transform.position);
             transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
     }
     
 }
 
Comment
Comments Locked · Show 21 · Share
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 kbeaud · Nov 24, 2012 at 07:50 PM 0
Share

OH $$anonymous$$Y GOSH!!!!!!!! I THAN$$anonymous$$ YOU SOOOO $$anonymous$$UCH! If I had to do that myself I probably could have never done it... Now just one thing I assume there are certain spots I need to change for each person that talks right?

avatar image kbeaud · Nov 24, 2012 at 07:51 PM 0
Share

And does the thing that needs the tag player.... $$anonymous$$e?

avatar image kbeaud · Nov 24, 2012 at 07:52 PM 0
Share

Oh and what's that whole section that is commented out?

avatar image greatestprez · Nov 24, 2012 at 07:53 PM 0
Share

Just apply the script to the character that you want to talk to and fill the conversation array with the conversation you want to have (make sure you change the size value to the amount of sentences you want). Example: in array slot 0 you could put something that says "Press "T" to talk to Bob" or "Bob: How Are you?" etc. Also, make sure that the character that you apply the script to has a large trigger collider attached directly to the character.

avatar image kbeaud · Nov 24, 2012 at 07:54 PM 0
Share

Great... And the commented out section?

Show more comments
avatar image
1

Answer by greatestprez · Nov 23, 2012 at 10:23 PM

You need to try and make it yourself. And if its too complex for you I recommend starting with simpler things. If you need help with coding, I would recommend buying a book on unity (Will Goldstone has a excellent book that really helped me when I started using unity), or reading the unity tutorials(Start with the 3rd person platformer). Good luck :)

Comment
Comments Locked · Show 7 · Share
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 kbeaud · Nov 23, 2012 at 10:42 PM 1
Share

I tried reading the tutorial... It well wouldn't load. I would love if anyone could give me this code, but till then I do as you say and try on my own.

avatar image greatestprez · Nov 23, 2012 at 10:53 PM 0
Share

if the tutorial didn't help you, get the book. it will help you a lot. :)

avatar image kbeaud · Nov 23, 2012 at 11:08 PM 0
Share

I will find a book. Is there anyway you can just give me the code, or am I gonna have to wait to read like two books, then try? If so I understand.

avatar image greatestprez · Nov 24, 2012 at 12:47 AM 0
Share

Ill try and help you..ill give you an example that you can build on if I get time :)

avatar image kbeaud · Nov 24, 2012 at 02:53 AM 0
Share

Dude thank you... I know this might be stupid question, but is a pm an email?

Show more comments

Follow this Question

Answers Answers and Comments

16 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

Related Questions

Snow based questions 2 Answers

In Game Animation 2 Answers

Stopping a function when another function running. 2 Answers

Multiple Animations for the Same GameObject 2 Answers

Need help converting Javascript to C# 3 Answers


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