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 krishn95 · Dec 19, 2019 at 03:31 PM · listtimesetexcel

how to set the value of my start time?

Hi, I am making a simulation in which the code reads the data from an excel sheet and makes a list. For example, in the list, it might say that at 100th sec, an object moves and at 105th sec it moves to another place. I would like to know how to set the start time of the simulation as 100th sec. So, the first second in the simulation = 100th sec and the 5th sec in simulation = 105th sec.

Below is the code I have written for reading the excel sheet and importing that data to a list.

/Sample Excel sheet data: Time ; Object no. ; Object coordinates 100th ; 1 ; (1,2,3) 105th ; 1 ; (2,2,3) 110th; 1 ; (4,2,3 ) 110th ; 2 ; (14,2,3) 115th ; 1 ; (6,2,3 ) 115th ; 2 ; (18,2,3) /

 public class CSVData
 {
     public int simsec;
     public int vnum;
     public string vtype;
     public float cfx;
     public float cfy;
     public float cfz;
     
 }
 List<CSVData> csv = new List<CSVData>();  


 public void Start() 
 {
     TextAsset traffic = Resources.Load<TextAsset>("traff");
     string[] data = traffic.text.Split(new char[] { '\n' });
     Debug.Log(data.Length);

     for (int i = 25; i < data.Length - 1; i++)
     {

         string[] row = data[i].Split(new char[] { ',' });
         CSVData c = new CSVData();
         int.TryParse(row[0], out c.simsec);
         //c.vtype = row[2];
         int.TryParse(row[1], out c.vnum);
         c.vtype = row[2];
         float.TryParse(row[3], out c.cfx);
         float.TryParse(row[4], out c.cfy);
         float.TryParse(row[5], out c.cfz);

         csv.Add(c);

     }



Comment
Add comment · Show 1
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 andrewsmithparkside · Dec 23, 2019 at 10:48 PM 0
Share

Could you give us an example of what you'd like to happen? What is getting increased, and where? Be specific.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by andrewsmithparkside · Dec 19, 2019 at 04:44 PM

I'm not quite sure what the second list is for aside from the tryparse, but do you want a whole new list every time you hit that suggested time, or just update the old list?

Anyways, I'd do something like,

float timestart = 0; timestart += Time.DeltaTime;

if timestart > timevarhere && timestart < timevar+1.2 (just to make sure it's not constantly doing it) { stuff here }

or if you want it to be neater int varint = 0;

if timestart > timevarhere && varint = 0 { stuff here var += 1; } Which will ensure it will only do it once.

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 krishn95 · Dec 19, 2019 at 06:13 PM 0
Share

I'm not sure what second list u are talking about. An can you explain what is suppose to be?

avatar image
0

Answer by Statement · Dec 19, 2019 at 06:23 PM

Perhaps something like this, where you add a startTime variable to offset the elapsed time and fast forward the simulation in Start according to your (hidden to us) logic.

 using System.Collections.Generic;
 using UnityEngine;
 
 public class CSVRead : MonoBehaviour
 {
     // Change this to 100 if you want to start at 100th second.
     public float startTime = 0.0f;
 
     public class CSVData
     {
         public int simsec;
         public int vnum;
         public string vtype;
         public float cfx;
         public float cfy;
         public float cfz;
 
     }
     List<CSVData> csv = new List<CSVData>();
 
     public void Start()
     {
         SetupCSV();
         FastForwardCSV(startTime);
     }
 
     void SetupCSV()
     {
         TextAsset traffic = Resources.Load<TextAsset>("traff");
         string[] data = traffic.text.Split(new char[] { '\n' });
         Debug.Log(data.Length);
         for (int i = 25; i < data.Length - 1; i++)
         {
             string[] row = data[i].Split(new char[] { ',' });
             CSVData c = new CSVData();
             int.TryParse(row[0], out c.simsec);
             int.TryParse(row[1], out c.vnum);
             c.vtype = row[2];
             float.TryParse(row[3], out c.cfx);
             float.TryParse(row[4], out c.cfy);
             float.TryParse(row[5], out c.cfz);
             csv.Add(c);
         }
     }
 
     void FastForwardCSV(float startTime)
     {
         foreach (var c in csv)
         {
             if (c.simsec < startTime)
             {
                 // Add code to move object to wherever it needs to be
             }
         }
     }
 
     void Update()
     {
         float time = Time.time + startTime;
         // Your ususal code, using time
     }
 }
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 krishn95 · Dec 19, 2019 at 06:50 PM 0
Share

Im not sure how this will work if (c.simsec < startTime)

I have updated my question with more info Could you please check it out

avatar image Statement krishn95 · Dec 20, 2019 at 01:06 PM 0
Share

I am unsure what you're asking about. I got the impression you wanted to start placing (driving, whatever) objects (vnum) to locations (cfx etc) at some time (simsec) and that you wanted to skip ahead 100 seconds in your list of objects.

The if (c.simsec < startTime) is there in FastForwardCSV to let all objects in your list get a chance to catch up with the simulation being skipped startTime seconds in time.

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

123 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 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

A node in a childnode? 1 Answer

Using scripts inside an Array 1 Answer

Set limit to 60 seconds 2 Answers

How to increase rate of a falling object in pooling object? 1 Answer

How do I make a button not interactable for a set amount of time after pressed? 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