- Home /
Gui or texture (ex. circle) on plane by click
Hi there!
I have character who is been moving by ClickToMove script and i searched around the web and pretty much on Unity Answers and doc. And i couldn't find anything that works for me.
So, i wanna create ar circle (2d texture or some simple black point - dont care)... leave a mark on clicked position, when player moves to position the circle disapears..
I dont want to someone code the script for me, but i would be very happy to give me some direction to look at. LineRenderer i think wouldn't be the right thing or just i have no idea how to use it in this situation, also tried projector - no success.
Ideal for my case would be : click > show texture > character reach destination > remove texture. The thing is - I dont know how to show that texture on plane. Can someone suggest something for me?
Perfect would be c# example.
Thanks. Sorry about english
Answer by nesis · Jan 16, 2014 at 10:05 AM
Rather than using a texture, you might be better off using either a projector or a mesh, and placing them so they're just above the ground. To get where the user clicked in C#, you'd do this in its Update() function:
public Transform indicator;
public void Update() {
if (Input.GetMouseButtonDown(0)) {
const float offset = 0.1f; //set this to whatever offset from the surface you want
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray,out hit, Mathf.Infinity)) {
indicator.position = hit.point + hit.normal * offset;
//alternatively, offset it upwards, depending on what you want
//indicator.position = hit.point + Vector3.up * offset;
}
}
}
Then for the indicator, you'd just need to, say, show it when it's beyond some distance from the player.
Your answer
Follow this Question
Related Questions
How to get texture coordinates without using MeshCollider? 0 Answers
So here is some really complicated question. 1 Answer
Dynamically changing a decals position on a mesh surface 2 Answers
How to make the Health bar on Enemys head not be in relation to Player(main) Camera? 2 Answers
Assigning UV Map to model at runtime 0 Answers