• 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 /
avatar image
0
Question by MikezNesh · Jul 21, 2010 at 06:19 AM · pathfindingdragtargetwaypoints

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?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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);     
         } 
 }   

}

Comment
Add comment · Show 2 · 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 MikezNesh · Jul 21, 2010 at 05:44 PM 0
Share

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?

avatar image MikezNesh · Jul 22, 2010 at 05:08 AM 0
Share

Pleas Help $$anonymous$$e!!!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

OnDrag Draw Line For Pathfinding... 1 Answer

PathFinding with fixed waypoints problem 1 Answer

error CS0161: not all code paths return a value 2 Answers

Firing at a target 1 Answer


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