Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 PuzzleBox · Nov 03, 2011 at 08:09 PM · collisionswitchwaypoint

Waypoints using a Switch...

I got script that chooses a new way-point when its triggered. It currently works but the clones that are spawning instantiate with another clones way-point and not the default way-point 0. How can I make each clone not effect each other?

 private var waypoint = 0;

 function OnTriggerEnter (other : Collider) {
     if (other.CompareTag("WayPointCube")){
         spot = Random.Range(0,2);
         Debug.Log("Hit");
         switch(spot){
             case 1:
                 waypoint = 2;
             break;
             
             case 2:
                 waypoint = 1;
             break;
             
             case 0:
                 waypoint = 0;
             break;
             }
         }
Comment
Add comment · Show 3
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 cj_coimbra · Nov 03, 2011 at 08:19 PM 0
Share

You will need to show how do you create your "WaypointCube", I mean, the script attached to the prefab, as well as how you handle the waypoint data structure.

But without knowing that maybe you could store your waypoints outside the WaypointCubes and set it´s destination point as the next waypoint from your new global waypoint list/stack at the moment right after their instantiation. Then, when you reach that WaypointCube´s destination point, you repeat the proccess...

avatar image PuzzleBox · Nov 03, 2011 at 08:40 PM 0
Share

I have this script as apart of an AI script, When the AI collides with an object with the tag "WayPointCube" the script is triggered. The way-points are in an Array. The variable "waypoint" is the number that is used to reference the transform within the array.

var target : Transform[];

var dir = (target[waypoint].position - transform.position).normalized;

avatar image syclamoth · Nov 03, 2011 at 11:20 PM 0
Share

How are you instantiating your clones? You should be using a prefab, not copying existing ones (unless there's a good reason to do it that way, which there sometimes is)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by cj_coimbra · Nov 03, 2011 at 08:57 PM

Try setting the line "private var waypoint = 0;" inside the Awake function of the script attached to the clone prefab.

Comment
Add comment · Show 1 · 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 PuzzleBox · Nov 03, 2011 at 11:06 PM 0
Share

No dice. Would disabling the function after it chooses a way point work?

avatar image
0

Answer by roamcel · Nov 05, 2011 at 05:40 AM

Quite certainly, what happens is that somehow all instances are 'sharing' the waypoint structure.

Since I guess you're using a script that's attached to a gameobject in the scene, and you somehow use that gameobject for all your instances... well, since there's -one- instance, there can be only -one- waypoints list!

The answer to your question is: create a "prefab out of the waypoints" and pass it as a "parameter" to your gameobjects after creation.

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

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Colliders and waypoints... 2 Answers

Switching between controllers - why do I have to press spacebar twice before it works? 1 Answer

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

Question on Vector3.Reflect() 2 Answers

What is the best way to script third person real-time action melee combat in C#? 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