マイロボットの作成




一定の間隔で砲弾の自動発射
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShotShell : MonoBehaviour
{
public GameObject shellPrefab;
private int count;
// FixedUpdateに変更(ポイント)
private void FixedUpdate()
{
count += 1;
if (count % 10 == 0) // 発射間隔は自由
{
GameObject shell = Instantiate(shellPrefab, transform.position, Quaternion.identity);
Rigidbody shellRb = shell.GetComponent<Rigidbody>();
shellRb.AddForce(transform.forward * 500); // 弾速は自由
Destroy(shell, 5.0f);
}
}
}








一定の間隔で砲弾の自動発射
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShotShell : MonoBehaviour
{
public GameObject shellPrefab;
private int count;
// FixedUpdateに変更(ポイント)
private void FixedUpdate()
{
count += 1;
if (count % 10 == 0) // 発射間隔は自由
{
GameObject shell = Instantiate(shellPrefab, transform.position, Quaternion.identity);
Rigidbody shellRb = shell.GetComponent<Rigidbody>();
shellRb.AddForce(transform.forward * 500); // 弾速は自由
Destroy(shell, 5.0f);
}
}
}




マイロボットの作成