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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by c4nert · Nov 10, 2012 at 12:33 AM · delayinvoke

Why is my program not working properly ?

Hello There, I'm trying to program an animation but I have problem. My animation have 3 part. Firstly, my camera is going somewhere I chose before and it's waiting on there 10sec. Secondly, the camera should go somewhere I chose in a different position but my counter is increasing immediately without wait the second step and it's going to 3rd step. Lastly,the third part is also that camera should go to a place I chose differently. And it's going there.

Why my counter increasing without wait in the 2nd Sec.

My codes:

using UnityEngine; using System.Collections;

public class move : MonoBehaviour {

public Transform target;

public int mSpeed=1;

public int rSpeed=1;

private GameObject go;

private float pre;

private int pos=0;

private Transform myTransform;

// Use this for initialization

void Awake(){

myTransform=transform;

}

void Start () {

 pos=1;

print(pos.ToString());

go=GameObject.FindGameObjectWithTag(pos.ToString());

target=go.transform;

}

// Update is called once per frame

void Update () {

myTransform.rotation=Quaternion.Slerp(myTransform.rotation,Quaternion.LookRotation(target.position - myTransform.position),rSpeed*Time.deltaTime);

if( (myTransform.position-target.position).magnitude>10){

myTransform.position += myTransform.forward*mSpeed*Time.deltaTime;

}

if((myTransform.position-target.position).magnitude<=10)

{

Invoke("PosPlus", 2);

}

}

void PosPlus (){

if(pos==1){

print("pos was:"+pos.ToString());

pos=2; }

else if(pos==2){

print("pos was:"+pos.ToString());

pos=3; }

print(pos.ToString());

go=GameObject.FindGameObjectWithTag(pos.ToString());

target=go.transform;

Invoke("Update",0);

}

}

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 Eric5h5 · Nov 10, 2012 at 01:11 AM 0
Share

Use the code button to format code when you post here please.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sparkzbarca · Nov 10, 2012 at 08:15 AM

on function start store timer.time as startingtime

 //the anding just allows for it to be approximately you could narrow it down alot if you //wanted to. right now it just makes sure it only triggers between 10 and 11 seconds. 
 //you can just do greater than, or the 20 second mark would trigger it as well to go 
 //to pos 1 and then you want it go to pos 2.
 if (starting + 10 < timer.time && starting + 11 > timer.time)
 {
 go to pos 1;
 }
  if(start + 20  < timer.timer && starting + 21 > timer.time)
 { 
 go to pos 2
 }
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

11 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

Related Questions

Access to float seconds ago 2 Answers

Help needed in invoke method... im trying to make the invoke delay start of the next scene but i couldn't? 0 Answers

Add delay to Fixed Update?,How to add a delay to moving object in Fixed Update? 0 Answers

strange behaviour for coroutine and invoke 1 Answer

Invoke Method Not Working Properly! 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