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 janeDoe9173 · Feb 20, 2016 at 10:52 AM · c#resethudstars

Can someone tell me whats missing on my script for resetting collected stars after completing level?

I am trying to make my collected stars reset after a level is completed. I now have it to where the score and the stars reset upon player death, However when the level is completed the star count remains upon entering next level. If anyone could help, I'd really appreciate it. `

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 using UnityEngine;
 
 public class LevelManager : MonoBehaviour 
 {
     public static LevelManager Instance { get; private set; }
 
     public Player Player { get; private set; }
     public CameraController Camera { get; private set; }
     public TimeSpan RunningTime { get { return DateTime.UtcNow - _started; } }
 
     public int CurrentTimeBonus
 
     {
         get
         {
             var secondDifference = (int) (BonusCutoffSeconds - RunningTime.TotalSeconds);
             return Mathf.Max (0, secondDifference) * BonusSecondMultiplier;
         }
     }
 
     private List<Checkpoint> _checkpoints;
     private int _currentCheckpointIndex;
     private DateTime _started;
     private int _savedPoints;
     private int _starsCollected;
 
     public Checkpoint DebugSpawn;
     public int BonusCutoffSeconds;
     public int BonusSecondMultiplier;
 
     public void Awake()
     {
         _savedPoints = GameManager.Instance.Points;
         _starsCollected = GameManager.Instance.Stars;
         Instance = this;
     }
 
     public void Start()
     {        
         _checkpoints = FindObjectsOfType<Checkpoint> ().OrderBy (t => t.transform.position.x).ToList ();
         _currentCheckpointIndex = _checkpoints.Count > 0 ? 0 : -1;
 
         Player = FindObjectOfType<Player> ();
         Camera = FindObjectOfType<CameraController> ();
 
         _started = DateTime.UtcNow;
 
         var listeners = FindObjectsOfType<MonoBehaviour> ().OfType<IPlayerRespawnListener> ();
         foreach (var listener in listeners) 
         {
             for (var i = _checkpoints.Count - 1; i >= 0; i --)
             {
                 var distance = ((MonoBehaviour)listener).transform.position.x - _checkpoints[i].transform.position.x;
                 if(distance < 0)
                     continue;
 
                 _checkpoints[i].AssignObjectToCheckpoint (listener);
                 break;
             }
         }
 
         #if UNITY_EDITOR
         if (DebugSpawn != null)
         DebugSpawn.SpawnPlayer (Player);
         else if (_currentCheckpointIndex != -1)
         _checkpoints [_currentCheckpointIndex].SpawnPlayer (Player);
         #else
 
         #endif
     }
 
     public void Update()
     {
         var isAtLastCheckpoint = _currentCheckpointIndex + 1 >= _checkpoints.Count;
         if (isAtLastCheckpoint)
             return;
 
         var distanceToNextCheckpoint = _checkpoints [_currentCheckpointIndex + 1].transform.position.x - Player.transform.position.x;
         if (distanceToNextCheckpoint >= 0)
             return;
 
         _checkpoints [_currentCheckpointIndex].PlayerLeftCheckpoint ();
         _currentCheckpointIndex++;
         _checkpoints [_currentCheckpointIndex].PlayerHitCheckpoint ();
 
         GameManager.Instance.AddPoints (CurrentTimeBonus);
 
         _savedPoints = GameManager.Instance.Points;
         _starsCollected = GameManager.Instance.Stars;
         _started = DateTime.UtcNow;
 
     }
 
     public void GotoNextLevel(string levelName)
     {
         StartCoroutine (GotoNextLevelCo (levelName));
     }
 
     private IEnumerator GotoNextLevelCo(string levelName)
     {
         Player.FinishLevel();
         GameManager.Instance.AddPoints(CurrentTimeBonus);
 
         FloatingText.Show ("Level Complete!", "CheckpointText", new CenteredTextPositioner (.2f));
         yield return new WaitForSeconds (1);
 
         FloatingText.Show(string.Format("{0} points!", GameManager.Instance.Points), "CheckpointText", new CenteredTextPositioner(.1f));
         yield return new WaitForSeconds(3f);
 
         if (string.IsNullOrEmpty(levelName))
             Application.LoadLevel("StartScreen");
         else
             Application.LoadLevel(levelName);
     }
 
     public void KillPlayer()
     {
         StartCoroutine (KillPLayerCo ());
     }
 
     private IEnumerator KillPLayerCo()
     {
         Player.Kill ();
         Camera.IsFollowing = false;
         yield return new WaitForSeconds (2f);
 
         Camera.IsFollowing = true;
 
         if (_currentCheckpointIndex != -1)
             _checkpoints [_currentCheckpointIndex].SpawnPlayer (Player);
 
         _started = DateTime.UtcNow;
         GameManager.Instance.ResetPoints (_savedPoints, _starsCollected);
     }
 }
 
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Maurice_B · Feb 20, 2016 at 01:03 PM

Hi, could you just show where the code to finish level is?

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 janeDoe9173 · Feb 20, 2016 at 07:09 PM 0
Share

public void GotoNextLevel(string levelName) { StartCoroutine (GotoNextLevelCo (levelName)); }

  private IEnumerator GotoNextLevelCo(string levelName)
  {
      Player.FinishLevel();
      Game$$anonymous$$anager.Instance.AddPoints(CurrentTimeBonus);
 
      FloatingText.Show ("Level Complete!", "CheckpointText", new CenteredTextPositioner (.2f));
      yield return new WaitForSeconds (1);
 
      FloatingText.Show(string.Format("{0} points!", Game$$anonymous$$anager.Instance.Points), "CheckpointText", new CenteredTextPositioner(.1f));
      yield return new WaitForSeconds(3f);
 
      if (string.IsNullOrEmpty(levelName))
          Application.LoadLevel("StartScreen");
      else
          Application.LoadLevel(levelName);
  }
 
avatar image janeDoe9173 · Feb 20, 2016 at 07:16 PM 0
Share

SOLVED.. I was putting Game$$anonymous$$anager.Instance.ResetPoints (starsCollected); in the wrong location.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Ball reset in Pong 1 Answer

Reset Raw UI Image For Audio Spectrum Data 0 Answers

Getting Hit direction to show hit indicator 1 Answer

2D Power up script not working 0 Answers

2D Power up script not working 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