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 /
  • Help Room /
avatar image
0
Question by xerxes78 · Dec 13, 2016 at 03:38 AM · c#objectdestroywaitforsecondstroubleshooting

Some coding help needed

Hey everyone, I am fairly new to coding and am looking for some help on a few issues.

Basically I am making a game thats an endless runner and am having issues with

  1. On start I have a countdown animation, but I can not get my object to wait for 4 seconds before taking off down the map. The only controls on the Player is left and right. It is coded so that it continues down the map automatically and the user will only have to swipe left or right to control the object.

  2. I also cannot figure how to play an exploding animation when it crashes. It just disappears and the game goes back to the scene and says MissingRefererenceException

Any help would be greatly appreciated! Thanks everyone for looking!

Comment
Add comment · Show 2
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 getyour411 · Dec 13, 2016 at 04:01 AM 0
Share

What have you tried for the "object must wait" - you added some tags but no code to know how you are doing that. Also include the code/line# (relevant section only please) that produces the $$anonymous$$issingRef

avatar image xerxes78 getyour411 · Dec 13, 2016 at 02:19 PM 0
Share

I have not tried that. I added the code to the last response if you would like to take a look at what I have so far

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by sumitb_mdi · Dec 13, 2016 at 04:08 AM

  1. To wait for 4 seconds, what you can do is make your Time.timeScale = 0, this will pause all the scripts. And start a Coroutine with WaitForSecondsRealtime, (Don't use WaitForSeconds as this is Time.timeScale dependent - so not good for your case )

     void Start()  {
             Time.timeScale = 0;
             StartCoroutine(InitialWait(4.0f));    //Time you want to wait in seconds.
         }
         
         private IEnumerator InitialWait(float waitTime) {
                    yield return new WaitForSecondsRealtime(waitTime);
                    Time.timeScale = 1.0f;
         }
    
    
    
  2. You can use existing assets from Asset store for your exploding animations. There are tons of freely available, just explore. Have a look at : Freely Available assets.

Comment
Add comment · Show 9 · 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 xerxes78 · Dec 13, 2016 at 02:16 PM 0
Share

Thank you for the response! I tried adding the code, but I ended up with multiple errors. Here is the code I am working with for the player controller. I also have Constant Force added to the game object so that it will automatically travel down the map in the Z direction. $$anonymous$$aybe this is my issue?

using UnityEngine; using System.Collections;

public class PlayerController : $$anonymous$$onoBehaviour

{

 void Start()
 {
     
 }

 void Awake()
 {
     
     ourVehicle = GetComponent<Rigidbody>();
 }

 Rigidbody ourVehicle;
 public float speed;
 public float tilt;
 public float power;

 


void FixedUpdate() {

     float moveHorizontal = Input.GetAxis("Horizontal");
     Vector3 movement = new Vector3(moveHorizontal, 2.0f);
     ourVehicle.velocity = movement * speed;
     ourVehicle.rotation = Quaternion.Euler(ourVehicle.velocity.z, 0.0f, ourVehicle.velocity.x * -tilt
     );
 }
 void OnCollisionEnter(Collision target)
 {
     if (target.gameObject.tag == "Lethal")
     {
         
         Destroy(gameObject);

     }
     if (target.gameObject.tag == "Diamond")
     {
         Destroy(target.gameObject);
     }
     
 }

}

avatar image sumitb_mdi · Dec 13, 2016 at 02:20 PM 0
Share

Can you paste the errors too that you are getting while executing these scripts.

avatar image xerxes78 sumitb_mdi · Dec 13, 2016 at 02:26 PM 0
Share

There isnt an error at the start. The issue is that the object takes off down the map during countdown. I have an animation that starts a countdown, 3, 2, 1, GO! I am trying to get it to takeoff after the animation.

The error I get on crashing into an object is this -

$$anonymous$$issingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. CameraController.LateUpdate () (at Assets/Scripts/CameraController.cs:27)

I am trying to play an explosion on crash but it just exits the scene once I hit something.

avatar image sumitb_mdi xerxes78 · Dec 13, 2016 at 02:34 PM 0
Share

The error says it all, what is your Code at line number 27 in CameraController.cs ?? You are surely accessing a destroyed object. If you want I can help you directly on a Skype Call, that would be quick. (SkypeID : sumitb.mdi )

Show more comments
avatar image xerxes78 sumitb_mdi · Dec 13, 2016 at 03:21 PM 0
Share

Update -

I figured out the wait time for 4 seconds code and it is working! There is a 4 second delay on start of the game, but there is one issue. The countdown is also paused and starts playing after the 4 seconds. How do I make the countdown play during the 4 second wait?

avatar image xerxes78 · Dec 13, 2016 at 02:22 PM 0
Share

Thanks for the responses! I have tried adding the Time Scale to the Start section of the code and it ended up producing tons of errors. Here is the code I have for the player controller. I have added Constant Force to the game object to get it to travel down the map automatically. $$anonymous$$aybe that is the issue I am running into?

As far as the explosions go, I have an explosion from the assest store, but when I try and code it to play it is not waiting the time to play the animation. I am getting the error in the camera follow script, I can post that as well if needed.

using UnityEngine; using System.Collections;

public class PlayerController : $$anonymous$$onoBehaviour

{

 void Start()
 {
     
 }

 void Awake()
 {
     
     ourVehicle = GetComponent<Rigidbody>();
 }

 Rigidbody ourVehicle;
 public float speed;
 public float tilt;
 public float power;

 


void FixedUpdate() {

     float moveHorizontal = Input.GetAxis("Horizontal");
     Vector3 movement = new Vector3(moveHorizontal, 2.0f);
     ourVehicle.velocity = movement * speed;
     ourVehicle.rotation = Quaternion.Euler(ourVehicle.velocity.z, 0.0f, ourVehicle.velocity.x * -tilt
     );
 }
 void OnCollisionEnter(Collision target)
 {
     if (target.gameObject.tag == "Lethal")
     {
         
         Destroy(gameObject);

     }
     if (target.gameObject.tag == "Diamond")
     {
         Destroy(target.gameObject);
     }
     
 }

}

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

8 People are following this question.

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

Related Questions

Destroy moving objcts through touch on screen 0 Answers

Destroy, deactive or hide 0 Answers

Instantiate an object and destroy it after given time 2 Answers

Destroy object on click? UNITY 2 Answers

Objects getting destroyed in unity test, but only sometimes in the phone app 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