Search Unity

SceneManager.LoadScene ("scenename") reloads scene, but not scripting.

Discussion in 'Scripting' started by MeiinWaffle, Nov 22, 2017.

  1. MeiinWaffle

    MeiinWaffle

    Joined:
    Nov 22, 2017
    Posts:
    2
    Unity Version 2017.2.0f3 Personal
    IDE Visual Studio for Mac Community version 7.2.2 (build 11)
    On Mac Mini Late 2012 macOS High Sierra version 10.13.1

    I'm following a tutorial through my class and as far as I know I've been following the tutorial to the letter.

    What we're doing is making an Angry Birds style game and I'm getting stuck on a reload script featured here:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class Resetter : MonoBehaviour
    7. {
    8.  
    9.     public Rigidbody2D rb2dProjectile;
    10.     public float resetSpeed = 0.025f;
    11.  
    12.     private float resetSpeedSqr;
    13.     private SpringJoint2D spring;
    14.  
    15.     // Use this for initialization
    16.     void Start()
    17.     {
    18.         resetSpeedSqr = resetSpeed * resetSpeed;
    19.         spring = rb2dProjectile.GetComponent<SpringJoint2D>();
    20.  
    21.     }
    22.  
    23.     // Update is called once per frame
    24.     void Update() //resets scene if R is pressed or if velocity goes below threshold
    25.     {
    26.         if (Input.GetKeyDown(KeyCode.R))
    27.         {
    28.             Reset();
    29.         }
    30.         if (spring == null && rb2dProjectile.velocity.sqrMagnitude < resetSpeedSqr)
    31.         {
    32.             Reset();
    33.         }
    34.     }
    35.  
    36.     void Reset() //loads Main scene
    37.     {
    38.         SceneManager.LoadScene ("Main");
    39.     }
    40.  
    41.     void OnTriggerExit2D(Collider2D other) //resets scene if rock exits boundary box
    42.     {
    43.         if (other.gameObject.GetComponent<Rigidbody2D>() == rb2dProjectile)
    44.         {
    45.             Reset();
    46.         }
    47.     }
    48. }
    What it does is reset the scene when rb2dProjectile exits a boundary box or slows to a certain threshold, or if the "R" key is pressed. While the scene resets on those conditions, the scripting does not reset. There are two other scripts used in this project thus far and I can post them if necessary. I didn't post them here because I don't want to clutter everything up.
     
  2. MeiinWaffle

    MeiinWaffle

    Joined:
    Nov 22, 2017
    Posts:
    2
    It started working with no intervention. No idea why, but whatever.