- Home /
Question is off-topic or not relevant
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.
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.
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.
are u kidding me ? ... i bet he didn't even bother to read a coding tutorial...
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.
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);
}
}
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?
And does the thing that needs the tag player.... $$anonymous$$e?
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.
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 :)
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.
if the tutorial didn't help you, get the book. it will help you a lot. :)
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.
Ill try and help you..ill give you an example that you can build on if I get time :)
Dude thank you... I know this might be stupid question, but is a pm an email?
Follow this Question
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