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 TheTurkeydipking · Dec 11, 2016 at 10:58 PM · freezescene-switching

Scene doesn't play when linked from outside

Heya Unity Answers,

I'm completely stuck on what to do. I've created a little project consisting of 3 scenes - a normal game scene, a main menu and a "cracked" game scene. The "cracked" and normal version of the scenes share a bunch of assets - mainly the player asset.

When I play the "cracked" scene from the editor or from the main menu, it works fine. However, when I play the normal scene, proceed into the main menu, and then onto the "cracked" scene everything just stays still. No animations, no sounds, nothing is happening. Unity doesn't crash, the Build Settings are also fine, so it must be something that happens between the normal scene and the "cracked" scene - some code freezing it up maybe? I read online that loops could cause this but as far as I'm aware I don't have any...

This is my player code, it's quite messy but it's a work in progress!

using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.SceneManagement;

public class PlayerMovement : MonoBehaviour {

 private int health;
 private bool canJump;
 private Rigidbody rigidbody;
 public int jumpstr;
 private CameraScript cameraScript;
 public float rotateSpeed = 70f;
 public int score;
 private float scoreTime = 0.0f;
 public GameObject inputButton;
 private AudioSource audioSource;
 public AudioClip skatejump;
 public AudioClip barrelbreak;
 public AudioClip skateland;
 public AudioClip munch;
 public Text scoreText;
 public ParticleEmitter bloodSplat;
 public float hunger;
 private float hungerTime = 0.0f;
 private NPCMovement npcMovement;
 private Scene scene;

 // Use this for initialization
 void Awake () {
 
     health = 6;
     score = 0;
     rigidbody = GetComponent<Rigidbody> ();
     cameraScript = GameObject.Find ("Manager").GetComponent<CameraScript> ();
     inputButton.SetActive(false);
     audioSource = this.gameObject.GetComponent<AudioSource> ();
     ScoreCounter ();
     transform.FindChild ("hitText").gameObject.SetActive (false);
     hunger = 100;
     scene = SceneManager.GetActiveScene ();
 }

 public void Damage()
 {
     health -= 1;
     score -= 1000;
     this.StartCoroutine (this.HitAnim ());
     if (health < 1) 
     {
         GameOver ();
     }
 }

 public int GetHealth()
 {
     return health;
 }

 // Update is called once per frame
 private void Update () 
 {

     scoreTime += Time.deltaTime;
     if (scoreTime >= 1) {
         score += (int)scoreTime * 5;
         scoreTime -= (int)scoreTime / 2;
         ScoreCounter ();
     }

     if (scene.name == "Cracked") {
         transform.position += transform.right * Time.deltaTime * 30;
         Debug.Log ("let'sgobois");
     }

     if(Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.Space))
     {
         if(canJump == true)
         {
             Debug.Log ("rekt");
             rigidbody.AddForce (new Vector3(0, jumpstr, 0), ForceMode.Impulse);
             canJump = false;
             audioSource.Stop ();
             audioSource.PlayOneShot(skatejump, 0.5f);
         }
     }

     if (transform.position.y < -2) {
         Debug.Log ("Game Over");
         GameOver ();
     }

     HungryHungryHippo ();

     if (hunger <= 0) {
         GameOver ();
     }

     if (hunger > 100) {
         hunger = 100;
     }
 }

 private void FixedUpdate()
 {
         if (cameraScript.transition == true) {
         if (Input.GetKey (KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) {
             transform.Rotate (Vector3.up * rotateSpeed * -Time.deltaTime);
         }
         if (Input.GetKey (KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) {
             transform.Rotate (Vector3.up * rotateSpeed * Time.deltaTime);
         }
     }
 }

 private void OnCollisionEnter(Collision col)
 {

     if (col.gameObject.tag == "ground") {
         canJump = true;
         audioSource.Play ();
         audioSource.PlayOneShot (skateland, 0.5f);
     }
     else if (col.gameObject.tag == "NPC") {
         Yummy ();
         npcMovement = GameObject.FindGameObjectWithTag("NPC").GetComponent<NPCMovement> ();
         npcMovement.DeadPygmy ();
     }
 }

 public void BreakBarrel()
 {
     audioSource.PlayOneShot (barrelbreak, 0.5f);
 }

 public void GameOver()
 {
     inputButton.SetActive (true);
     Time.timeScale = 0;
     audioSource.Stop();
     scoreTime = 0;
 }

 public void ScoreCounter()
 {
     scoreText.text = "Score: " + score.ToString();
 }


 private IEnumerator HitAnim()
 {
     transform.FindChild ("hitText").gameObject.SetActive (true);
     transform.FindChild ("hitText").gameObject.GetComponent<Animation> ().Play ("hitAnim");
     yield return new WaitForSeconds (0.2f);
     transform.FindChild ("hitText").gameObject.SetActive (false);
 }

 public void Yummy()
 {
     Debug.Log ("hunger went down!");
     hunger += 10;
     audioSource.PlayOneShot (munch, 0.5f);
     bloodSplat.enabled = true;
 }

 public void HungryHungryHippo()
 {
     Scene scene = SceneManager.GetActiveScene ();

     if (scene.name == "Cracked") {
         hungerTime += Time.deltaTime;
         if (hungerTime >= 1) {
             hunger -= (int)hungerTime * 1;
             hungerTime -= (int)hungerTime / 1;
             Debug.Log ("hunger: " + hunger);
         }
     }
 }

}

Any help would be insanely appreciated!

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 TheTurkeydipking · Dec 11, 2016 at 11:07 PM 0
Share

Well as it turns out I totally forgot that I added time.timescale = 0 in my code (been coding for many hours so tired). setting it to 1 on start fixed my issue!

1 Reply

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

Answer by TheTurkeydipking · Dec 11, 2016 at 11:07 PM

My silly mistake. Timescale was set to 0, had to reset it to 1 to fix it!

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

57 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

Related Questions

Game doesn't work anymore when exported for android. 1 Answer

SceneManager.LoadScene causes total freeze 1 Answer

Xbox UWP Game Crashing Upon Loading 0 Answers

Hi, i know this been here before,. My Unity freezed on build .shaderasset if i remember correcty. so i ended process with task manager and now i cant open the project. 0 Answers

Unity3d Mac project freezes when importing ogg/mv4 files on external hard disk 4 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