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
5ab16613
Commit
5ab16613
authored
Nov 03, 2016
by
Jordan McKenney
Browse files
Added a fireball prefab and script to spawn fireballs
parent
b75c40b0
Changes
5
Show whitespace changes
Inline
Side-by-side
Assets/Prefabs.meta
View file @
5ab16613
fileFormatVersion: 2
guid:
6d652580
3f9c
2de4e8233fc51322fdc5
guid: 3f
d
9c
01e8800fc54681146f720a0d04b
folderAsset: yes
timeCreated: 147
6403153
timeCreated: 147
7008945
licenseType: Free
DefaultImporter:
userData:
...
...
Assets/Prefabs/FireballProjectile.prefab
View file @
5ab16613
No preview for this file type
Assets/script/FireballMove.cs
View file @
5ab16613
...
...
@@ -4,26 +4,22 @@ using System.Collections;
public
class
FireballMove
:
MonoBehaviour
{
public
float
speed
;
private
Rigidbody2D
fireRB
;
public
int
direction
;
public
Vector2
move
;
// Use this for initialization
void
Start
()
{
fireRB
=
GetComponent
<
Rigidbody2D
>
();
/*
if (direction == 0)
move = new Vector2 (1,0);
if (direction == 1)
move = new Vector2 (0,1);
if (direction == 2)
move = new Vector2 (-1,0);
if (direction == 3)
move = new Vector2 (0,-1);
*/
fireRB
.
velocity
=
(
move
*
speed
);
}
// Update is called once per frame
void
Update
()
{
fireRB
.
MovePosition
((
Vector2
)
transform
.
position
+
move
*
speed
);
//fireRB.MovePosition((Vector2)transform.position + move*speed);
}
void
OnCollisionEnter2D
(
Collision2D
c
){
Destroy
(
this
.
gameObject
);
}
}
Assets/script/HeroAttackController.cs
View file @
5ab16613
...
...
@@ -4,12 +4,14 @@ using System.Collections;
public
class
HeroAttackController
:
MonoBehaviour
{
enum
ability
{
fireball
,
water
,
others
};
p
ublic
int
direction
;
p
rivate
int
direction
;
public
float
speed
;
private
ability
currentAbility
=
ability
.
fireball
;
public
GameObject
FireballPrefab
;
private
Vector3
LastInput
=
new
Vector3
(
0
,
1
,
0
);
// Use this for initialization
void
Start
()
{
...
...
@@ -17,13 +19,26 @@ public class HeroAttackController : MonoBehaviour {
// Update is called once per frame
void
Update
(){
Vector3
input
=
new
Vector3
(
Input
.
GetAxisRaw
(
"Horizontal"
),
Input
.
GetAxisRaw
(
"Vertical"
),
0
);
if
(
input
.
x
==
0
&&
input
.
y
==
0
)
{
//do nothing
}
else
if
(
input
.
y
!=
0
)
{
LastInput
=
new
Vector3
(
0
,
input
.
y
,
0
);
}
else
{
LastInput
=
new
Vector3
(
input
.
x
,
0
,
0
);
}
if
(
Input
.
GetButtonDown
(
"Fire1"
)){
switch
(
currentAbility
)
{
case
ability
.
fireball
:
GameObject
clone
=
Instantiate
(
FireballPrefab
,
new
Vector3
(
0
,
0
,
0
),
Quaternion
.
identity
)
as
GameObject
;
clone
.
GetComponent
<
FireballMove
>
().
move
=
GetComponent
<
PlayerAnimation
>
().
lastInput
;
clone
.
GetComponent
<
FireballMove
>
().
speed
=
speed
;
Vector3
pos
=
GetComponent
<
Transform
>
().
position
;
GameObject
clone
=
Instantiate
(
FireballPrefab
,
pos
,
Quaternion
.
identity
)
as
GameObject
;
clone
.
GetComponent
<
FireballMove
>().
move
=
LastInput
;
clone
.
GetComponent
<
FireballMove
>().
speed
=
speed
;
Debug
.
Log
(
"fireball"
);
break
;
...
...
@@ -38,5 +53,8 @@ public class HeroAttackController : MonoBehaviour {
}
}
public
Vector3
GetLastDirection4
(){
return
LastInput
;
}
}
ProjectSettings/TagManager.asset
View file @
5ab16613
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