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
-1
Question by kiyoshi357 · Sep 08, 2013 at 06:37 AM · movementspawning

Can someone help me with my script. It won't work for me.

Okay so the script I have here is written in C# and it is designed so that when the period key is pressed the player is warped to a random object in the game. This object is a sphere I have called medium and has a collier on it and "in trigger" is checked on each of them. It is set up with the intention of warping randomly between them in the game. When the key is pressed I get no reaction at all in the scene so and I have tried using the medium one object as the object it looks for as well as the whole prefab I have these spawn points in. So what have I done wrong? Code below: using UnityEngine; using System.Collections;

 public class warp: MonoBehaviour 
 {
     public GameObject[] obj;
     private int counter;
     
     void Start()
     {
         counter = 0;
     }
     
     void Update()
     {
         if(Input.GetKeyUp(KeyCode.Period))
         {
             this.transform.position = new Vector3(obj[counter].transform.position.x, obj[counter].transform.position.y, obj[counter].transform.position.z);
             counter++;
             
             if(counter >= obj.Length) counter = 0;
         }
     }
 }

Comment
Add comment · Show 15
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 fafase · Sep 08, 2013 at 06:38 AM 0
Share

Did you add the script to the object? Just in case.

avatar image Dr.Z · Sep 08, 2013 at 06:49 AM 0
Share

Just in case too, you added some GameObjects in your array ?

avatar image bubzy · Sep 08, 2013 at 07:45 AM 0
Share

you will need something like obj = GameObject.FindObjectsWithTag("spawnPoint"); to populate your obj[] array with positions, as it stands now, all of the positions are the same, so while it may be working, you wont notice anything at all. incidentally, this may not be random as you are incrementing the counter variable by a set condition. you might want to use Random.Range($$anonymous$$,max) ins$$anonymous$$d

http://docs.unity3d.com/Documentation/ScriptReference/GameObject.FindGameObjectsWithTag.html

avatar image Sajidfarooq · Sep 08, 2013 at 08:03 AM 0
Share

@Bubzy: The positions are not all the same. They depend on the array that is passed in "obj". Also, as it stands, he "circulates" over all the points one-by-one, rather than jumping purely randomly (as you pointed out). I am not sure if pure randomly is something he wants.

avatar image kiyoshi357 · Sep 08, 2013 at 09:31 AM 0
Share

@Dr.Z and @Sajidfarooq I'm sorry but I'm sort of new and don't quite know what you mean with either of these. Sorry can you please explain or help with it a little bit please.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Help with movement script 2 Answers

Vehicle help 1 Answer

how do i use two animations on the same object?? 1 Answer

Activating Audio When Hitting a collider 2 Answers


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