砲塔の角度を上下できるようにする(TPSモード)

砲塔を上下させる
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TurretController : MonoBehaviour
{
private Vector3 angle;
public GameObject head;
void Start()
{
angle = transform.eulerAngles;
}
void Update()
{
if(Input.GetKey(KeyCode.Q))
{
angle.x -= 0.2f;
if(angle.x < -30)
{
angle.x = -30;
}
transform.eulerAngles = new Vector3(angle.x, head.transform.eulerAngles.y, 0);
}
else if(Input.GetKey(KeyCode.E))
{
angle.x += 0.2f;
if(angle.x > 0)
{
angle.x = 0;
}
transform.eulerAngles = new Vector3(angle.x, head.transform.eulerAngles.y, 0);
}
}
}



モーター音の追加
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TurretController : MonoBehaviour
{
private Vector3 angle;
public GameObject head;
// ★サウンド
private AudioSource audioSource;
void Start()
{
angle = transform.eulerAngles;
// ★サウンド
audioSource = GetComponent<AudioSource>();
audioSource.enabled = false;
}
void Update()
{
if (Input.GetKey(KeyCode.Q))
{
// ★サウンド
audioSource.enabled = true;
angle.x -= 0.2f;
if (angle.x < -30)
{
angle.x = -30;
}
transform.eulerAngles = new Vector3(angle.x, head.transform.eulerAngles.y, 0);
}
else if (Input.GetKey(KeyCode.E))
{
// ★サウンド
audioSource.enabled = true;
angle.x += 0.2f;
if (angle.x > 0)
{
angle.x = 0;
}
transform.eulerAngles = new Vector3(angle.x, head.transform.eulerAngles.y, 0);
}
else // ★サウンド
{
audioSource.enabled = false;
}
}
}



砲塔を上下させる
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TurretController : MonoBehaviour
{
private Vector3 angle;
public GameObject head;
void Start()
{
angle = transform.eulerAngles;
}
void Update()
{
if(Input.GetKey(KeyCode.Q))
{
angle.x -= 0.2f;
if(angle.x < -30)
{
angle.x = -30;
}
transform.eulerAngles = new Vector3(angle.x, head.transform.eulerAngles.y, 0);
}
else if(Input.GetKey(KeyCode.E))
{
angle.x += 0.2f;
if(angle.x > 0)
{
angle.x = 0;
}
transform.eulerAngles = new Vector3(angle.x, head.transform.eulerAngles.y, 0);
}
}
}



モーター音の追加
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TurretController : MonoBehaviour
{
private Vector3 angle;
public GameObject head;
// ★サウンド
private AudioSource audioSource;
void Start()
{
angle = transform.eulerAngles;
// ★サウンド
audioSource = GetComponent<AudioSource>();
audioSource.enabled = false;
}
void Update()
{
if (Input.GetKey(KeyCode.Q))
{
// ★サウンド
audioSource.enabled = true;
angle.x -= 0.2f;
if (angle.x < -30)
{
angle.x = -30;
}
transform.eulerAngles = new Vector3(angle.x, head.transform.eulerAngles.y, 0);
}
else if (Input.GetKey(KeyCode.E))
{
// ★サウンド
audioSource.enabled = true;
angle.x += 0.2f;
if (angle.x > 0)
{
angle.x = 0;
}
transform.eulerAngles = new Vector3(angle.x, head.transform.eulerAngles.y, 0);
}
else // ★サウンド
{
audioSource.enabled = false;
}
}
}


砲塔の角度を上下できるようにする(TPSモード)