Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gadig
four
Commits
0d90c74c
Commit
0d90c74c
authored
Nov 18, 2016
by
Luke A Smith
Browse files
Merge branch 'floorSwitch' into 'master'
Floor switch See merge request
!21
parents
7fb86304
804e8c42
Changes
2
Hide whitespace changes
Inline
Side-by-side
Assets/Prefabs/Environment/FloorSwitch.prefab
0 → 100644
View file @
0d90c74c
File added
Assets/script/FloorSwitch.cs
0 → 100644
View file @
0d90c74c
using
UnityEngine
;
using
System.Collections
;
public
class
FloorSwitch
:
MonoBehaviour
{
//Ignore sprite renderer in file and set image useing first place in list
public
GameObject
player
;
public
bool
isSwitchOn
=
false
;
public
Sprite
[]
sprites
;
public
bool
isSwitchBack
=
true
;
private
Collider2D
pCol
;
private
bool
charIsOn
=
false
;
private
SpriteRenderer
spriteRenderer
;
// Use this for initialization
void
Start
()
{
//Sets sprite to first frame
pCol
=
player
.
GetComponent
<
Collider2D
>();
spriteRenderer
=
GetComponent
<
Renderer
>()
as
SpriteRenderer
;
spriteRenderer
.
sprite
=
sprites
[
0
];
}
void
OnTriggerEnter2D
(
Collider2D
col
)
{
//Debug.Log(col.name);
if
(
col
==
pCol
)
{
//Debug.Log("somthing moving on");
//Turns on bool and changes sprite
isSwitchOn
=
true
;
spriteRenderer
.
sprite
=
sprites
[
1
];
}
}
void
OnTriggerExit2D
(
Collider2D
colE
)
{
if
(
colE
==
pCol
&&
isSwitchBack
==
true
)
{
//Debug.Log("somthing moving off");
//Turns off bool and changes sprite
isSwitchOn
=
false
;
spriteRenderer
.
sprite
=
sprites
[
0
];
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment