敵が「跳ね返る」FireBallを投げる








FireShot
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Wizard : MonoBehaviour
{
public Vector2[] warpPos;
private int num;
private SpriteRenderer spriteRenderer;
// ★追加(FireShot)
public GameObject fireBallPrefab;
private void Start()
{
spriteRenderer = GetComponent<SpriteRenderer>();
}
public void Warp()
{
num = Random.Range(0, warpPos.Length);
this.transform.position = warpPos[num];
if (num == 1 || num == 2)
{
spriteRenderer.flipX = true;
}
else
{
spriteRenderer.flipX = false;
}
}
// ★追加(FireShot)
public void FireShot()
{
GameObject fireBall = Instantiate(fireBallPrefab, transform.position, Quaternion.identity);
Rigidbody2D fireBallRb2d = fireBall.GetComponent<Rigidbody2D>();
Destroy(fireBall, 5.0f);
// 「right」「left」で飛ばす方向をコントロール(自分のゲームに合わせること)
if (num == 1 || num == 2)
{
fireBallRb2d.AddForce(Vector2.right * 600);
}
else
{
fireBallRb2d.AddForce(Vector2.left * 600);
}
}
}



【2022版】DarkCastle(全39回)
他のコースを見る







FireShot
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Wizard : MonoBehaviour
{
public Vector2[] warpPos;
private int num;
private SpriteRenderer spriteRenderer;
// ★追加(FireShot)
public GameObject fireBallPrefab;
private void Start()
{
spriteRenderer = GetComponent<SpriteRenderer>();
}
public void Warp()
{
num = Random.Range(0, warpPos.Length);
this.transform.position = warpPos[num];
if (num == 1 || num == 2)
{
spriteRenderer.flipX = true;
}
else
{
spriteRenderer.flipX = false;
}
}
// ★追加(FireShot)
public void FireShot()
{
GameObject fireBall = Instantiate(fireBallPrefab, transform.position, Quaternion.identity);
Rigidbody2D fireBallRb2d = fireBall.GetComponent<Rigidbody2D>();
Destroy(fireBall, 5.0f);
// 「right」「left」で飛ばす方向をコントロール(自分のゲームに合わせること)
if (num == 1 || num == 2)
{
fireBallRb2d.AddForce(Vector2.right * 600);
}
else
{
fireBallRb2d.AddForce(Vector2.left * 600);
}
}
}



敵が「跳ね返る」FireBallを投げる