x


Maintain variable values while changing levels

How do I maintain the values of my variables when I am changing from one scene to the next? Like with character health, everything gets restarted, even when I use DontDestroyOnLoad(random script). What are some good techniques that I can use?

more ▼

asked Oct 19 '10 at 12:14 AM

Kevin 4 gravatar image

Kevin 4
11 6 7 10

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Have you tried creating a gameobject, attaching a controller script that manages player health and such on it, then calling DontDestroyOnLoad on the gameobject upon Awake like so:

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {

    void Awake() {
        DontDestroyOnLoad(transform.gameObject);
    }
}
more ▼

answered Oct 19 '10 at 02:17 AM

zannghast gravatar image

zannghast
526 11 14 26

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x820
x263
x123

asked: Oct 19 '10 at 12:14 AM

Seen: 780 times

Last Updated: Oct 19 '10 at 12:14 AM