Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SceneSwitch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
unity
SceneSwitch
Commits
32f3563c
Commit
32f3563c
authored
4 years ago
by
David Huss
Browse files
Options
Downloads
Patches
Plain Diff
Add Data.cs
parent
2d7fefb0
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Assets/Data.cs
+61
-0
61 additions, 0 deletions
Assets/Data.cs
Assets/SceneSwitch.cs
+1
-1
1 addition, 1 deletion
Assets/SceneSwitch.cs
README.md
+8
-3
8 additions, 3 deletions
README.md
with
70 additions
and
4 deletions
Assets/Data.cs
0 → 100644
+
61
−
0
View file @
32f3563c
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
using
UnityEngine.SceneManagement
;
public
class
Data
:
MonoBehaviour
{
public
bool
debug
=
true
;
public
static
Data
instance
;
public
string
currentScene
;
public
List
<
string
>
PlayedList
=
new
List
<
string
>();
public
List
<
string
>
VisitedScenes
=
new
List
<
string
>();
void
Awake
()
{
if
(
instance
==
null
)
{
instance
=
this
;
DontDestroyOnLoad
(
this
.
gameObject
);
}
if
(
currentScene
==
""
)
{
currentScene
=
SceneManager
.
GetActiveScene
().
name
;
RegisterScene
(
currentScene
);
}
Debug
.
LogFormat
(
"Current Scene after Awake is: {0}"
,
currentScene
);
}
public
void
RegisterSound
(
string
name
)
{
Debug
.
LogFormat
(
"Registering Sound as Played: {0}"
,
name
);
PlayedList
.
Add
(
name
);
}
public
bool
PlayedSound
(
string
name
)
{
return
PlayedList
.
Contains
(
name
);
}
public
void
UpdateScene
(
string
SceneName
){
// Unloading old scene
SceneManager
.
UnloadSceneAsync
(
currentScene
);
Debug
.
LogFormat
(
"Scene Switch from {0} to {1} completed"
,
currentScene
,
SceneName
);
// Updating new scene
currentScene
=
SceneName
;
RegisterScene
(
SceneName
);
}
public
void
RegisterScene
(
string
name
)
{
if
(!
WasThereBefore
(
name
))
{
VisitedScenes
.
Add
(
name
);
Debug
.
LogFormat
(
"Registering Scene as Visited: {0}"
,
name
);
}
}
// Return true if the scene was visited before
public
bool
WasThereBefore
(
string
name
)
{
return
VisitedScenes
.
Contains
(
name
);
}
// Return true if the current scene was visited before
public
bool
WasHereBefore
()
{
return
VisitedScenes
.
Contains
(
currentScene
);
}
}
This diff is collapsed.
Click to expand it.
Assets/SceneSwitch.cs
+
1
−
1
View file @
32f3563c
...
...
@@ -111,7 +111,7 @@ public class SceneSwitch : MonoBehaviour
yield
return
null
;
}
//
Data.instance.UpdateScene(SceneName);
Data
.
instance
.
UpdateScene
(
SceneName
);
}
}
This diff is collapsed.
Click to expand it.
README.md
+
8
−
3
View file @
32f3563c
...
...
@@ -2,7 +2,12 @@
Allows you to switch the active Scene when a Triggervolume is entered, exited or when you stay in a trigger volume for long enough
1.
Copy the Script
`Assets/SceneSwitch.cs`
to your assets folder
2.
Drag
it
onto the Trigger Volume
1.
Copy the Script
`Assets/SceneSwitch.cs`
and
`Assets/Data.cs`
to your assets folder
2.
Drag
`SceneSwitch.cs`
onto the Trigger Volume
3.
Enter a Scene Name (for the target Scene)
4.
Select a mode (On Enter, On Exit, Countdown)
5.
Drag
`Data.cs`
onto an empty Gameobject called "Data"
Data.cs can be used to transfer Data between scenes
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment