Fireballs continue in direction of click
This commit is contained in:
parent
c43c4a6f12
commit
55dd251d3d
3 changed files with 7 additions and 13 deletions
4
Assets/Scenes/Gameplay.unity
generated
4
Assets/Scenes/Gameplay.unity
generated
|
@ -362,7 +362,7 @@ Transform:
|
||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 433189272}
|
m_GameObject: {fileID: 433189272}
|
||||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: 9.76, y: 0.18, z: 0}
|
m_LocalPosition: {x: 9.76, y: 0.18, z: 0}
|
||||||
m_LocalScale: {x: 2.501405, y: 1.9675635, z: 1.0282}
|
m_LocalScale: {x: 2.501405, y: 1.9675635, z: 1.0282}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
|
@ -563,7 +563,7 @@ Transform:
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 569685893}
|
m_GameObject: {fileID: 569685893}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: -0.097918645, y: -0.20009108, z: -1}
|
m_LocalPosition: {x: -0.097918645, y: -0.20009108, z: -10}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 1027402150}
|
- {fileID: 1027402150}
|
||||||
|
|
|
@ -6,7 +6,6 @@ public class Fireball : MonoBehaviour
|
||||||
{
|
{
|
||||||
public float speed = 1.0f;
|
public float speed = 1.0f;
|
||||||
public AudioSource[] shootSounds;
|
public AudioSource[] shootSounds;
|
||||||
public Vector3 destination;
|
|
||||||
private int shootSoundVariations = 5;
|
private int shootSoundVariations = 5;
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
|
@ -21,7 +20,6 @@ public class Fireball : MonoBehaviour
|
||||||
|
|
||||||
void Move()
|
void Move()
|
||||||
{
|
{
|
||||||
float step = speed * Time.deltaTime;
|
transform.position += transform.up * speed * Time.deltaTime * -1;
|
||||||
transform.position = Vector3.MoveTowards(transform.position, destination, step);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,22 +20,18 @@ public class FireballSpawner : MonoBehaviour
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
if (timeBetweenShots > 0)
|
if (timeBetweenShots > 0) timeBetweenShots -= Time.deltaTime;
|
||||||
{
|
else if (Input.GetMouseButtonDown(0)) ShootFireball();
|
||||||
timeBetweenShots -= Time.deltaTime;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
if (Input.GetMouseButtonDown(0)) ShootFireball();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShootFireball()
|
void ShootFireball()
|
||||||
{
|
{
|
||||||
Vector3 mouseClickFromCamera = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
Vector3 mouseClickFromCamera = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||||
mouseClickFromCamera.z = 0;
|
mouseClickFromCamera.z = 0;
|
||||||
|
Vector3 angleToClick = dragonHead.transform.position - mouseClickFromCamera;
|
||||||
|
|
||||||
GameObject spawnedFireball = Instantiate(fireball, fireballSource.transform.position, Quaternion.identity);
|
GameObject spawnedFireball = Instantiate(fireball, fireballSource.transform.position, Quaternion.identity);
|
||||||
spawnedFireball.GetComponent<Fireball>().destination = mouseClickFromCamera;
|
spawnedFireball.transform.rotation = Quaternion.LookRotation(Vector3.forward, angleToClick);
|
||||||
|
|
||||||
timeBetweenShots = originalTimeBetweenShots;
|
timeBetweenShots = originalTimeBetweenShots;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue