マイロボットの作成1





砲弾を発射する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShotShell : MonoBehaviour
{
public GameObject shellPrefab;
public float shotSpeed;
public AudioClip shotSound;
public float interval;
void Start()
{
InvokeRepeating("Shot", 0.5f, interval);
}
void Shot()
{
GameObject shell = Instantiate(shellPrefab, transform.position, transform.rotation);
Rigidbody shellRb = shell.GetComponent<Rigidbody>();
shellRb.AddForce(transform.forward * shotSpeed);
Destroy(shell, 5.0f);
AudioSource.PlayClipAtPoint(shotSound, transform.position);
}
}




【2019版】TowerD I(基礎/全10回)
1 | 敵ロボットの作成&前進 |
2 | 敵ロボットをターンさせる1 |
3 | 敵ロボットをターンさせる2 |
4 | 敵ロボットにHPをつける |
5 | ロボットを生み出す装置を作る |
6 | マイロボットの作成1 |
7 | マイロボットにライフタイムを設定する |
8 | マイロボットの作成2 |
9 | ★チェックポイント |
10 | ★チャレンジ |





砲弾を発射する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShotShell : MonoBehaviour
{
public GameObject shellPrefab;
public float shotSpeed;
public AudioClip shotSound;
public float interval;
void Start()
{
InvokeRepeating("Shot", 0.5f, interval);
}
void Shot()
{
GameObject shell = Instantiate(shellPrefab, transform.position, transform.rotation);
Rigidbody shellRb = shell.GetComponent<Rigidbody>();
shellRb.AddForce(transform.forward * shotSpeed);
Destroy(shell, 5.0f);
AudioSource.PlayClipAtPoint(shotSound, transform.position);
}
}




マイロボットの作成1