空中から攻撃してくる敵の作成

AngelShot
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AngelShot : MonoBehaviour
{
public GameObject fireBallPrefab;
private GameObject target;
void Start()
{
target = GameObject.Find("Player");
}
// アニメーションから実行する
public void ShotFireBall()
{
GameObject fireBall = Instantiate(fireBallPrefab, transform.position, Quaternion.identity);
Rigidbody2D fireBallRb2d = fireBall.GetComponent<Rigidbody2D>();
// Playerに向かって発射する
Vector2 dic = transform.position - target.transform.position;
fireBallRb2d.AddForce(-dic * 50); // 必ず「-」をつけること(ポイント)
Destroy(fireBall, 5.0f);
}
}




【2022版】DarkCastle(全39回)
他のコースを見る
AngelShot
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AngelShot : MonoBehaviour
{
public GameObject fireBallPrefab;
private GameObject target;
void Start()
{
target = GameObject.Find("Player");
}
// アニメーションから実行する
public void ShotFireBall()
{
GameObject fireBall = Instantiate(fireBallPrefab, transform.position, Quaternion.identity);
Rigidbody2D fireBallRb2d = fireBall.GetComponent<Rigidbody2D>();
// Playerに向かって発射する
Vector2 dic = transform.position - target.transform.position;
fireBallRb2d.AddForce(-dic * 50); // 必ず「-」をつけること(ポイント)
Destroy(fireBall, 5.0f);
}
}




空中から攻撃してくる敵の作成