S
S
SDHOPS2016-07-02 16:23:32
Unity
SDHOPS, 2016-07-02 16:23:32

How to change the size of an object when moving to another scene?

There is a character customization menu, as you probably already understood, you need to save all customization changes, transfer the same object directly to the scene with the game itself, for this the simplest DontDestroyOnLoad function is used, the script is exactly the same as here: docs.unity3d.com/ ScriptReference/Object.DontDestro...
The problem is that the character is too big in the other scene, what changes should be made to the script to bring it, but already in a small size?
PS: I also added a camera to the character in the customization menu and turned it off, again, what needs to be entered in the script so that when the object is transferred to the next scene, it turns on?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Gaydak, 2016-07-04
@SDHOPS

The most obviously simple option is to keep the same scale in both scenes (and there will be fewer problems in the future)
And if through a script, then "adjust" the scale with handles.
https://docs.unity3d.com/ScriptReference/Transform...

void Example() {
        transform.localScale = new Vector3(5, 5, 5);
    }

in general, as I understand it, you are looking for something like
https://docs.unity3d.com/ScriptReference/MonoBehav...
to determine that you are in another scene?!
And about the camera - save a link to it (on gameobject) and just SetActive(bool f);
public class ExampleClass : MonoBehaviour
{
  //назначить в редакторе или в Awake() методе найти главную камеру
  //сам факт получить ссылку на камеру
  public GameObject cameraGO;
    void OnLevelWasLoaded(int level) {
        if (level == 13)//номер уровня или проверку по имени сделать
            {cameraGO.SetActive(true);}        
    }
}

And a little boredom. For good, all this customization of the object should be saved and described by some structure.
In the spirit -> Parts List, and each part has a Size, Color and Strength.
In order not to transfer through an indestructible object, but by saving and transferring the , describing such a structure, it was possible to restore the customized view.
There will be an opportunity to save at least two, three, four types of customization.
(As I understand it, you seem to be a tri-dash and I hope you explained it clearly in general terms)
Well, after that you can already make patterns-shmaters.

M
MrDywar Pichugin, 2016-07-02
@Dywar

There is a character - an object.
There is its size, this state. The State
pattern suggests itself . On loading the scene, you can substitute the state you need for the object, and it will change.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question