戦車から砲弾を発射する1(直線軌道)








砲弾の発射(直線軌道)
using UnityEngine;
public class ShotShell : MonoBehaviour
{
// ★インプットシステム
private InputSystem_Actions isa;
public GameObject shellPrefab;
public AudioClip shotSound;
public float shotSpeed;
public GameObject shotPoint;
void Start()
{
// ★インプットシステム
isa = new InputSystem_Actions();
isa.Enable();
}
void Update()
{
// ★インプットシステム
// 「Shot」に定義されたボタンを押した時(条件)
if (isa.Player.Shot.triggered)
{
GameObject shell = Instantiate(shellPrefab, shotPoint.transform.position, Quaternion.identity);
Rigidbody shellRb = shell.GetComponent<Rigidbody>();
shellRb.AddForce(transform.forward * shotSpeed);
Destroy(shell, 3.0f);
AudioSource.PlayClipAtPoint(shotSound, transform.position);
}
}
}






【Unity6版】BattleTank(全31回)
他のコースを見る







砲弾の発射(直線軌道)
using UnityEngine;
public class ShotShell : MonoBehaviour
{
// ★インプットシステム
private InputSystem_Actions isa;
public GameObject shellPrefab;
public AudioClip shotSound;
public float shotSpeed;
public GameObject shotPoint;
void Start()
{
// ★インプットシステム
isa = new InputSystem_Actions();
isa.Enable();
}
void Update()
{
// ★インプットシステム
// 「Shot」に定義されたボタンを押した時(条件)
if (isa.Player.Shot.triggered)
{
GameObject shell = Instantiate(shellPrefab, shotPoint.transform.position, Quaternion.identity);
Rigidbody shellRb = shell.GetComponent<Rigidbody>();
shellRb.AddForce(transform.forward * shotSpeed);
Destroy(shell, 3.0f);
AudioSource.PlayClipAtPoint(shotSound, transform.position);
}
}
}






戦車から砲弾を発射する1(直線軌道)