init
This commit is contained in:
commit
862afc9b7a
478 changed files with 197737 additions and 0 deletions
53
Assets/Scripts/Missile.cs
Normal file
53
Assets/Scripts/Missile.cs
Normal file
|
@ -0,0 +1,53 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Missile : MonoBehaviour
|
||||
{
|
||||
Transform player;
|
||||
public float RotateSpeed, speed;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
player = GameObject.FindGameObjectWithTag("Player").transform;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
float AngleRad = Mathf.Atan2(player.position.y - transform.position.y, player.position.x - transform.position.x);
|
||||
float AngleDeg = (180 / Mathf.PI) * AngleRad;
|
||||
/*if (AngleDeg > transform.rotation.z)
|
||||
AngleDeg -= 360;
|
||||
float DistanceNegative = transform.rotation.z - AngleDeg;
|
||||
if (AngleDeg > transform.rotation.z)
|
||||
AngleDeg += 360;
|
||||
if (AngleDeg < transform.rotation.z)
|
||||
AngleDeg += 360;
|
||||
float DistancePositive = AngleDeg - transform.rotation.z;
|
||||
float distance = 0;
|
||||
if (Mathf.Abs(DistancePositive) > Mathf.Abs(DistanceNegative))
|
||||
distance = DistanceNegative;
|
||||
else distance = DistancePositive;
|
||||
float rotatespeedclone;
|
||||
if (distance < RotateSpeed)
|
||||
rotatespeedclone = distance;
|
||||
else
|
||||
rotatespeedclone = RotateSpeed;
|
||||
transform.Rotate(Vector3.forward * (DistancePositive > DistanceNegative ? -1 : 1) * rotatespeedclone * Time.deltaTime);
|
||||
*/
|
||||
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(0, 0, AngleDeg), RotateSpeed * Time.deltaTime);
|
||||
transform.Translate(Vector3.right * speed * Time.deltaTime, Space.Self);
|
||||
}
|
||||
private void OnCollisionEnter2D(Collision2D collision)
|
||||
{
|
||||
if (collision.transform.tag == "Player")
|
||||
{
|
||||
collision.transform.GetComponent<PlayerStats>().Die();
|
||||
}else if (collision.transform.tag == "Boss")
|
||||
{
|
||||
collision.transform.GetComponent<Boss>().Health -= 1;
|
||||
}
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue