FireBallの作成





自動で移動する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveObject : MonoBehaviour
{
public float speed;
void Update()
{
transform.Translate(new Vector2(-1, 0) * Time.deltaTime * speed);
}
}



ぶつかったら自分を破壊する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyObject : MonoBehaviour
{
private void OnCollisionEnter2D(Collision2D collision)
{
// 何かにぶつかったら、自分を破壊する
Destroy(this.gameObject);
}
}






自己破壊(アニメーションから実行)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SelfDestroy : MonoBehaviour
{
// このメソッドは外部から呼び出すので、必ず「public」にすること(重要)
public void DestroyExplosion()
{
Destroy(this.gameObject);
}
}








エフェクトを出す
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyObject : MonoBehaviour
{
// ★追加(エフェクト)
public GameObject effectPrefab;
private void OnCollisionEnter2D(Collision2D collision)
{
Destroy(this.gameObject);
// ★追加(エフェクト)
Instantiate(effectPrefab, transform.position, Quaternion.identity);
}
}



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




自動で移動する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveObject : MonoBehaviour
{
public float speed;
void Update()
{
transform.Translate(new Vector2(-1, 0) * Time.deltaTime * speed);
}
}



ぶつかったら自分を破壊する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyObject : MonoBehaviour
{
private void OnCollisionEnter2D(Collision2D collision)
{
// 何かにぶつかったら、自分を破壊する
Destroy(this.gameObject);
}
}






自己破壊(アニメーションから実行)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SelfDestroy : MonoBehaviour
{
// このメソッドは外部から呼び出すので、必ず「public」にすること(重要)
public void DestroyExplosion()
{
Destroy(this.gameObject);
}
}








エフェクトを出す
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyObject : MonoBehaviour
{
// ★追加(エフェクト)
public GameObject effectPrefab;
private void OnCollisionEnter2D(Collision2D collision)
{
Destroy(this.gameObject);
// ★追加(エフェクト)
Instantiate(effectPrefab, transform.position, Quaternion.identity);
}
}



FireBallの作成