Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
Birb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gadig
Birb
Commits
50916e2f
Commit
50916e2f
authored
Mar 03, 2017
by
Luke A Smith
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'enemyHorizontal' into 'master'
enemy fixes See merge request
!28
parents
1e755e8d
08b6797d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
0 deletions
+83
-0
Assets/Scripts/Enemy/BaseEnemy.cs
Assets/Scripts/Enemy/BaseEnemy.cs
+40
-0
Assets/Scripts/Enemy/HorizontalEnemy.cs
Assets/Scripts/Enemy/HorizontalEnemy.cs
+22
-0
Assets/Scripts/Enemy/VerticalEnemy.cs
Assets/Scripts/Enemy/VerticalEnemy.cs
+21
-0
No files found.
Assets/Scripts/Enemy/BaseEnemy.cs
0 → 100644
View file @
50916e2f
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
BaseEnemy
:
MonoBehaviour
{
public
float
speed
=
2f
;
Rigidbody2D
body
;
protected
SpriteRenderer
sr
;
protected
float
startMoveTime
;
public
Transform
rightCollisionPos
;
public
Transform
leftCollisionPos
;
void
Start
()
{
body
=
GetComponent
<
Rigidbody2D
>();
sr
=
GetComponent
<
SpriteRenderer
>();
startMoveTime
=
Time
.
time
+
.
4f
;
}
protected
void
Move
(
Vector2
dir
,
bool
isFlipped
)
{
body
.
transform
.
Translate
((
isFlipped
?
-
dir
:
dir
)
*
speed
*
Time
.
deltaTime
);
}
protected
bool
CheckCollision
(
Vector2
dir
,
bool
isFlipped
)
{
Vector3
position
=
isFlipped
?
leftCollisionPos
.
position
:
rightCollisionPos
.
position
;
Debug
.
DrawRay
(
position
,
(
isFlipped
?
-
dir
:
dir
)
*
.
1f
,
Color
.
blue
,
.
1f
);
Debug
.
DrawRay
(
position
,
-
transform
.
up
*
.
1f
,
Color
.
red
,
.
1f
);
RaycastHit2D
hitSide
=
Physics2D
.
Raycast
(
position
,
isFlipped
?
-
dir
:
dir
,
.
1f
);
RaycastHit2D
hitDown
=
Physics2D
.
Raycast
(
position
,
-
transform
.
up
,
.
1f
);
if
(
hitDown
.
collider
!=
null
&&
hitSide
.
collider
==
null
)
{
return
true
;
}
return
false
;
}
}
Assets/Scripts/Enemy/HorizontalEnemy.cs
0 → 100644
View file @
50916e2f
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
HorizontalEnemy
:
BaseEnemy
{
// Update is called once per frame
void
Update
()
{
if
(
CheckCollision
(
transform
.
right
,
sr
.
flipX
))
{
if
(
startMoveTime
<
Time
.
time
)
{
Move
(
transform
.
right
,
sr
.
flipX
);
}
}
else
{
sr
.
flipX
=
!
sr
.
flipX
;
}
}
}
Assets/Scripts/Enemy/VerticalEnemy.cs
0 → 100644
View file @
50916e2f
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
VerticalEnemy
:
BaseEnemy
{
public
bool
leftWall
;
void
Update
()
{
if
(
CheckCollision
(
transform
.
right
,
leftWall
?
!
sr
.
flipX
:
sr
.
flipX
))
{
if
(
startMoveTime
<
Time
.
time
)
{
Move
(-
transform
.
up
,
sr
.
flipX
);
}
}
else
{
sr
.
flipX
=
!
sr
.
flipX
;
}
}
}
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