Now, the plan says that when the player touches the place, a script is activated that changes the string to what should go there, for Example:
-String is empty
-Player touches Area → String changes to: “I should get going now.”
-String changes back.
I have a little problem that causes all the other ones: I’m a Unity-Noob.
How do I mark the area? I don’t know.
How do I put a String in the Text? I don’t know.
How do I write a script that changes the String? I don’t know.
Does this plan even make any sense? I DON’T KNOW.
Mark the area by creating an empty game object. Attach a collider to this, for example a box collider. Move the object where you want the area to be and make the box collider what ever size you need.
Attach a script with something like this to the empty object:
using System.Diagnostics;
using System.Net.Mime;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ShowText : MonoBehaviour
{
private Text message;
void Start()
{
message = GameObject.Find("Message").GetComponent<Text>();
message.text = "";
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Player")
{
message.text = "Hello there!";
}
}
void OnTriggerExit2D(Collider2D other)
{
if (other.gameObject.tag == "Player")
{
message.text = "";
}
}
}
The script assumes that you have placed an UI Text somewhere in the scene and that it is named “Message”. It also assumes that your player is tagged with “Player”.
Thanks for your help!
Honestly, I couldn’t test the script because it gave me the “The referenced script on this Behavior is missing” error. I’trying to fix this one first and then try your code.
Sadly, the script did not work properly. It turns the text to “”, which means the first part (the void start() ) worked, but nothing changed when I hit the GameObject. It has got a BoxCollider and the Player is tagged Player, the Text is called message too. I don’t see the problem.
What can I do now?
I have another question, so…
I want that the character stops movement for a while (input disabled), so that i can run through a short cutscene.
I have a script that looks something like this:
using System.Diagnostics;
using System.Net.Mime;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ShowMessage : MonoBehaviour
{
private Text message;
void Start()
{
message = GameObject.Find("Message").GetComponent<Text>();
message.text = "";
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Player")
{
yield return new WaitForSeconds(5f);
//At this point, the input should be disabled.
message.text = "I better get going now...";
message.text = "";
yield return new WaitForSeconds(5f);
//Here, the input should be enabledd again
Destroy (this);
}
}
It would be very nice if you could help me with this too…
Thanks in advance!