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
67992c6c
Commit
67992c6c
authored
Oct 06, 2016
by
Cody A Burchett
Browse files
flame crab
parent
b1edcb29
Changes
5
Hide whitespace changes
Inline
Side-by-side
Assets/scene/cburchetTesting.unity
0 → 100644
View file @
67992c6c
File added
Assets/scene/cburchetTesting.unity.meta
0 → 100644
View file @
67992c6c
fileFormatVersion: 2
guid: 3449ac6e2a03fd54fa5d10fa4b3518ac
timeCreated: 1475798950
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
Assets/script/FlameCrab.cs
0 → 100644
View file @
67992c6c
using
UnityEngine
;
using
System.Collections
;
public
class
FlameCrab
:
MonoBehaviour
{
public
float
moveDelay
=
5f
;
public
float
speed
=
5f
;
public
float
health
=
10f
;
float
nextMove
=
0f
;
Vector3
targetLocation
=
-
Vector3
.
up
;
Rigidbody2D
body
;
// Use this for initialization
void
Start
()
{
body
=
GetComponent
<
Rigidbody2D
>();
}
// Update is called once per frame
void
Update
()
{
if
(
nextMove
<
Time
.
time
)
{
if
(
targetLocation
!=
-
Vector3
.
up
)
{
if
((
transform
.
position
-
targetLocation
).
sqrMagnitude
>
.
15f
)
{
Move
();
}
else
{
nextMove
=
Time
.
time
+
moveDelay
;
targetLocation
=
-
Vector3
.
up
;
}
}
else
{
//find new target location to right or left of enemy
int
spacesToMove
=
Random
.
Range
(-
5
,
6
);
RaycastHit2D
hit
=
Physics2D
.
Raycast
(
transform
.
position
,
transform
.
right
,
spacesToMove
,
1
);
if
(
hit
.
collider
)
{
targetLocation
=
hit
.
point
;
}
else
{
targetLocation
=
transform
.
position
+
(
transform
.
right
*
spacesToMove
);
}
}
}
}
void
Move
()
{
Vector3
dir
=
targetLocation
-
transform
.
position
;
body
.
transform
.
Translate
(
dir
.
normalized
*
speed
*
Time
.
deltaTime
);
}
}
Assets/script/FlameCrab.cs.meta
0 → 100644
View file @
67992c6c
fileFormatVersion: 2
guid: ad04fbd2b7592974baa491ea766a0337
timeCreated: 1475799560
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
ProjectSettings/TagManager.asset
View file @
67992c6c
No preview for this file type
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