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 RmurilloM · Apr 22, 2012 at 02:50 AM · c#listrandomanimationscharacters

How can I use just one script to move randomly several characters from an array?

Hi guys!.. I have trying for a couple of days to do that, but now I'm stuck.

I have a List of Characters. After several time, I want to select one randomly and I give it the animation "walk" until the character arrive to a point. When the character arrives to the point, it needs to stay there for a while and then, after several seconds, it needs to turn around (eulerAngles(0, 180, 0)) and walk back until a point and them I need to destroy that character and select a new one from the list and do the same thing!

This is the script I have so far:

using UnityEngine; using System.Collections; using System.Collections.Generic;

public class Please : MonoBehaviour { public List CharacterList = new List(); public Vector3 Target = new Vector3(-18.03273f, 0.09936082f, 1.479195f); float speed = 3f; public GameObject characterChosen;

 bool doIt = true;
 void Start ()
 {
     ChooseCharacter();
 }
 
 
 void Update ()
 {
     Invoke ("Move", 5);
 }
 
 void Move(){
     if (characterChosen.transform.position.z <= 1.910322) { 
             characterChosen.transform.animation.CrossFade ("walk");
             characterChosen.transform.Translate (Vector3.forward * Time.deltaTime * speed);
         }
         else {
             characterChosen.transform.animation.CrossFade("idle1");
             Invoke("GoBack", 10);
             StartCoroutine (MoveRest());
         }
 }
 IEnumerator MoveRest(){
 yield return new WaitForSeconds(10);
     if (doIt == true) {//This is for avoid that ChooseCharacter is selected several times
         doIt = false;
         ChooseCharacter();
     }        
     if (characterChosen.transform.position.z <= 1.910322) {
         characterChosen.transform.animation.CrossFade ("walk");
         characterChosen.transform.Translate (Vector3.forward * Time.deltaTime * speed);
     }
     else {
         characterChosen.transform.animation.CrossFade("idle1");
         Invoke("GoBack", 5);
     }
 }
 void GoBack(){
     if (characterChosen.transform.position.z >= -37.63817) {
         characterChosen.transform.eulerAngles = new Vector3(0,180,0);
         characterChosen.transform.animation.CrossFade ("walk");
         characterChosen.transform.Translate  (Vector3.forward * Time.deltaTime * speed);
     }    
 }
 
 void ChooseCharacter(){
     if (CharacterList.Count >= 1) {
         int characterIndex = Random.Range (0, CharacterList.Count);
         characterChosen = CharacterList[characterIndex];
         CharacterList.RemoveAt (characterIndex);
     }    
 }

} Please, I really need your help! So, How can I use this script to select the characters from a random List and do what I wrote below above?

Thanks so much in advance!

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Selecting random indexes without repetition 3 Answers

Printing an ordered list 1 Answer

Add random amount of random items from one list to another? 2 Answers

(c#) display a random string at game over 2 Answers

List of List of Booleans function giving weird results 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