Search code examples
c#objectscene

Changing an object in one scene changes it in 2


I'm using Unity and I have a scene with a tablet in it. I copied this scene and changed a few things but besides a few texture changes its the same scene. In the second scene I changed the animation on the tablet to a different animation and it worked fine. But going back to the first scene I see that it changed the animation on both scenes. I have a lot of scripts that refer to the name of the tablet object and script so is there any way to fix this without having to remake the tablet and all the scripts? I don't have object prefab. And the animations are completely different. The only thing that is shared is the object name and script.


Solution

  • In order to solve your problem, you will need to make two different animations for each of the tablets.

    Let's say you have animation 1 applied to tablet 1 you copy everything and now you have tablet 2 with animation 1 as well now if you edit animation 1 while working on scene 2 (with tablet 2), scene 1 (with tablet 1) will automatically get affected since it is also referring to the same animation 1

    So what you have to do is the following: -make two separate animations : animation 1 and animation 2 -assign to each tablet a different animation

    Finally, there are two methods you can apply:

    1. In your code you will need to make a field that will allow you to control which animation or animator controller to trigger/use (google it)

    OR

    1. You can add two animation clips on one controller and control a Boolean (or integer) that will choose which one to trigger as in the picture below:

    First, make 2 separate animations: enter image description here

    Then, go to animator, right click and add empty state, then right click on it and do set as layer default state Link to it the two animations you have

    enter image description here

    Go to parameters -> add a new Boolean and make one of the transition true and the other false

    enter image description here

    enter image description here

    and finally, you can do the following in your code:

    add public bool animationtype that you can control from your inspector (if you set it to true animation 1 will play , if false animation 2 will play) and you can use:

    whatevername.SetBool("whatevername", animationtype);
    

    If you have more than two animations, consider using Integer instead of Boolean.