Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 husnain_rao · Feb 17, 2019 at 11:22 AM · transform.positionienumeratorreset-position

store positions in array

I want top store my car Positions in an array so that i can use them to reset my carafter crash but i am unable to do this. this is my code

 Vector3[] positions = new Vector3[10];
 void Start()
 {
     StartCoroutine ("CrashCheck");
     }
 private IEnumerator CrashCheck(){
             while(n<10)
             {
                 yield return new WaitForSeconds(1);
                 positions [n] = car [GameCOnstant.carNumber].transform.position;
                 n += 1;
             }
             n = 0;
         }

when i debug my positions it alwasy display(0,0,0).

Comment
Add comment · Show 4
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 zereda-games · Feb 17, 2019 at 11:50 AM 0
Share

is the GameCOnstant on each of the cars and each one have their one value 0-9 as a list can not be null or empty and first element is 0.

avatar image zereda-games zereda-games · Feb 17, 2019 at 12:18 PM 0
Share

or on the car controller preferably

Here is what i came up with in 10 $$anonymous$$

 public static class Cars{
     public  static Car carNumber1_Race1 = new Car (0,"$$anonymous$$ichael Schumacher ", Resource.Load<GameObject>("CarsFolder/SchumacherCar1"))
     public  static Car carNumber2_Race1 = new Car (1,"Lewis Hamilton", Resource.Load<GameObject>("CarsFolder/HamiltonCar_Race1")
     public  static Car carNumber3_Race1 = new Car (2,"Sebastian Vettel", Resource.Load<GameObject>("CarsFolder/VettelCar1")
     public  static Car carNumber4_Race1 = new Car (3,"Charles Leclerc", Resource.Load<GameObject>("CarsFolder/LeclercCar_Race1")
     public  static Car carNumber5_Race1 = new Car (4,"$$anonymous$$y Sirotkin", Resource.Load<GameObject>("CarsFolder/SirotkinCar_Race1")
     public  static Car carNumber6_Race1 = new Car (5,"Pierre Gasly", Resource.Load<GameObject>("CarsFolder/GaslyCar_Race1")
     public  static Car carNumber7_Race1 = new Car (6,"Brendon Hartley", Resource.Load<GameObject>("CarsFolder/SchumacherCar1")
     public  static Car carNumber8_Race1 = new Car (7,"Lance Stroll", Resource.Load<GameObject>("CarsFolder/StrollCar_Race1")
     public  static Car carNumber9_Race1 = new Car (8,"Antonio Giovinazzi", Resource.Load<GameObject>("CarsFolder/GiovinazziCar1")
     public  static Car carNumber10_Race1 = new Car (9,"Player", Resource.Load<GameObject>("CarsFolder/PlayerCars"+Selection)

     public static Selection;
     public static List<Car>CarListForRace1=new List<Car>(){carNumber1_Race1, carNumber2_Race1, carNumber3_Race1, carNumber4_Race1, carNumber5_Race1, carNumber6_Race1, carNumber7_Race1, carNumber8_Race1, carNumber9_Race1, carNumber10_Race1 }

 }

 public struct Car
 {
     public int ID;
     public string Name;
     public GameObject CarPrefab;

     public Car(int id){
        ID=id;
        Name="";
        CarPrefab=new GameObject();
     }
     public Car(int id, string driversName){
        ID=id;
        Name=driversName;
        CarPrefab=new GameObject();
     }
     public Car(int id, string driversName, GameObject carPrefab){
        ID=id;
        Name=driversName;
        CarPrefab=carPrefab;
     }
 }

 public class Cars$$anonymous$$anager:$$anonymous$$onoBehaviour{
        public List<bool>Races new List<bool>(25){true};
        public List<Car>CarsInRace = new List<Car>();
        public List<GameObject>CarInRacePrefabs=new List<GameObject>();
        public int RaceSelection;
        void Awake(){
           for(int i=0;i<Cars.CarListForRace1.Count;i++){
                if(Equals(i,RaceSelection)&&Equals(Races[i],true) ){
                               CarsInRace =GetCurrentRacesCars(i);
                }
           }
        }

        List<CarsInRace>GetCurrentRacesCars(int selection){
             if(Equals(selection,Cars.Selection)&&Equals(selection,RaceSelection)){
                    return Cars.CarListForRace1;
             } else{
                   Debug.LogException(new System.Exception("You forgot to set the selection on the static class."));
             }
             // to return the correct cars. this script is not complete. will always return same list
        }
 }











avatar image RobAnthem · Feb 17, 2019 at 06:55 PM 0
Share

You could always do something like this.

 public class TimeController : $$anonymous$$onoBehaviour
 {
      public class PositionTimeStamp
      {
           public Vector3 position;
           public System.DateTime time;
      }
      public List<PositionTimeStamp> timeStamps;
      public int maxStoredStamps;
      void Awake()
      {
           timeStamps = new List<PositionTimeStamp>();
           timeStamps.Add(new PositionTimeStamp() { position = transform.position, time = System.DateTime.Now });
      }
      void Update()
      {
           if (isCarCrashed)
                return;
           if (timeStamps.Count + 1 > maxStoredStamps)
           {
                timeStamps.Remove(timeStamps[0]);
           }
            timeStamps.Add(new PositionTimeStamp() { position = transform.position, time = System.DateTime.Now });
      }
 }
avatar image sean244 · Feb 17, 2019 at 08:31 PM 0
Share

You're not showing us your entire code. I don't see anywhere in your code where the variable 'n' is declared.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by husnain_rao · Feb 17, 2019 at 06:43 PM

hey @zereda-games thanx for your reply. Gameconstant contains the value of selected car number. my question is that i want to store my car position in every second. so that when the car is crashed i can reset my car on some previously saved position.

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

103 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera object remember position after scene reload 0 Answers

My objects are not moving when collided with player when trying to reset their position after a timer. 0 Answers

How to move an object smoothly while in a Coroutine / Ienumerator? 3 Answers

My character's y position gets reset on play. 0 Answers

Simple way to reset GameObjects? 0 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