- Home /
Passing stuff from script to script (setting change-able waypoints) ....
I am almost done with my game like a game called Phage Wars. In this game you click/drag and release your drag on an enemy building to send troops to attack that building.
I got the dragging done but I need to know how to tell where to send the troops.
Therefore I set up waypoints. Unfortunately the waypoint location is not fixed so I need to know how to set up a way to add the waypoint location where you release your click (which gameObject released on).
I have created a variable called target with a Transform property defined (var target : Transform;). Then I am trying to find where you click and make the waypoint location there.
Unfortunately the waypoint system is in a different script.
So how will I set up a way to access the location of the waypoint in the waypoint script from another script?
Answer by Julian-Glenn · Jul 21, 2010 at 06:32 AM
Aron's work on A* AI might be of use. http://www.arongranberg.com/unity/a-pathfinding/
Or to just place a prefab where you clicked the mouse use something like this:
var Prefab : GameObject ;
function Update () { if (Input.GetMouseButtonDown(0)) { var ray: Ray = Camera.main.ScreenPointToRay(Input.mousePosition); var hit: RaycastHit;
if (Physics.Raycast(ray, hit)) {
Instantiate(Prefab, hit.point, Quaternion.identity);
}
}
}
A few problems... I want to make it so that each player follows his own waypoint not all instantiated units will follow one waypoint. How will I do that?
Your answer
Follow this Question
Related Questions
OnDrag Draw Line For Pathfinding... 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How to drag a GameObject with touch but at a limited speed 1 Answer
Static target in the srcipt for my Prefab 2 Answers
How to make an AI of a car to jump if there is any obstacle 2 Answers