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
de9143a9
Commit
de9143a9
authored
Nov 17, 2016
by
James D Fonda
Browse files
Adding basic slime script
parent
44408661
Changes
1
Hide whitespace changes
Inline
Side-by-side
Assets/Scripts/basic_slime_script.cs
0 → 100644
View file @
de9143a9
using
UnityEngine
;
using
System.Collections
;
public
class
basic_slime_script
:
MonoBehaviour
{
private
Vector3
player_position
;
private
Vector3
slime_position
;
private
GameObject
player
;
private
float
x_diff
;
private
float
y_diff
;
// Use this for initialization
void
Start
()
{
player
=
GameObject
.
FindGameObjectWithTag
(
"Player"
);
}
// Update is called once per frame
void
Update
()
{
//get position of player character
player_position
=
player
.
transform
.
position
;
//get position of slime
slime_position
=
transform
.
position
;
//compare to position of slime (self)
x_diff
=
player_position
.
x
-
slime_position
.
x
;
y_diff
=
player_position
.
y
-
slime_position
.
y
;
if
(
Mathf
.
Abs
(
x_diff
)
>=
Mathf
.
Abs
(
y_diff
))
{
//if move is valid, then move
if
(
x_diff
<
0
)
{
if
(
World
.
get
((
int
)(
slime_position
.
x
-
1
+
0.5
),
(
int
)(
slime_position
.
y
+
0.5
)).
walkable
==
true
)
transform
.
position
+=
Vector3
.
left
;
}
if
(
x_diff
>
0
)
{
if
(
World
.
get
((
int
)(
slime_position
.
x
+
1
+
0.5
),
(
int
)(
slime_position
.
y
+
0.5
)).
walkable
==
true
)
transform
.
position
+=
Vector3
.
right
;
}
}
else
{
//if move is valid, then move
if
(
y_diff
<
0
)
{
if
(
World
.
get
((
int
)(
slime_position
.
x
+
0.5
),
(
int
)(
slime_position
.
y
-
1
+
0.5
)).
walkable
==
true
)
transform
.
position
+=
Vector3
.
down
;
}
if
(
y_diff
>
0
)
{
if
(
World
.
get
((
int
)(
slime_position
.
x
+
0.5
),
(
int
)(
slime_position
.
y
+
1
+
0.5
)).
walkable
==
true
)
transform
.
position
+=
Vector3
.
up
;
}
}
}
}
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