照準器で狙った位置にライフル弾を発射する







ShotBulletを切り替える
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMoveController : MonoBehaviour {
public GameObject player;
public float rotateSpeed;
private const float angleLimitUp = 30f;
private const float angleLimitDown = -60f;
public Camera mainCamera;
public Camera subCamera;
private Vector3 angle;
public GameObject aimObject;
public GameObject rifle;
// ★追加
public GameObject shotBullet2;
void Start(){
mainCamera.enabled = true;
subCamera.enabled = false;
}
void Update () {
transform.position = player.transform.position;
angle = player.transform.eulerAngles;
transform.eulerAngles = new Vector3 (transform.eulerAngles.x, angle.y, transform.eulerAngles.z);
if (Input.GetMouseButton (0)) {
RotateCameraAngle ();
mainCamera.enabled = false;
subCamera.enabled = true;
aimObject.SetActive(true);
rifle.SetActive (false);
// ★追加
// サブカメラの時だけ、ShotBullet2をオンにする。
shotBullet2.SetActive(true);
} else {
mainCamera.enabled = true;
subCamera.enabled = false;
aimObject.SetActive(false);
rifle.SetActive (true);
// ★追加
shotBullet2.SetActive(false);
}
float angle_x = 180f <= transform.eulerAngles.x ? transform.eulerAngles.x - 360f : transform.eulerAngles.x;
transform.eulerAngles = new Vector3(Mathf.Clamp(angle_x, angleLimitDown, angleLimitUp), transform.eulerAngles.y, transform.eulerAngles.z);
}
void RotateCameraAngle(){
Vector3 angle = new Vector3(Input.GetAxis("Mouse X") * rotateSpeed, -Input.GetAxis("Mouse Y") *rotateSpeed, 0);
transform.eulerAngles += new Vector3(angle.y, angle.x, 0);
}
}



EscapeCombat(メモ)
他のコースを見る






ShotBulletを切り替える
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMoveController : MonoBehaviour {
public GameObject player;
public float rotateSpeed;
private const float angleLimitUp = 30f;
private const float angleLimitDown = -60f;
public Camera mainCamera;
public Camera subCamera;
private Vector3 angle;
public GameObject aimObject;
public GameObject rifle;
// ★追加
public GameObject shotBullet2;
void Start(){
mainCamera.enabled = true;
subCamera.enabled = false;
}
void Update () {
transform.position = player.transform.position;
angle = player.transform.eulerAngles;
transform.eulerAngles = new Vector3 (transform.eulerAngles.x, angle.y, transform.eulerAngles.z);
if (Input.GetMouseButton (0)) {
RotateCameraAngle ();
mainCamera.enabled = false;
subCamera.enabled = true;
aimObject.SetActive(true);
rifle.SetActive (false);
// ★追加
// サブカメラの時だけ、ShotBullet2をオンにする。
shotBullet2.SetActive(true);
} else {
mainCamera.enabled = true;
subCamera.enabled = false;
aimObject.SetActive(false);
rifle.SetActive (true);
// ★追加
shotBullet2.SetActive(false);
}
float angle_x = 180f <= transform.eulerAngles.x ? transform.eulerAngles.x - 360f : transform.eulerAngles.x;
transform.eulerAngles = new Vector3(Mathf.Clamp(angle_x, angleLimitDown, angleLimitUp), transform.eulerAngles.y, transform.eulerAngles.z);
}
void RotateCameraAngle(){
Vector3 angle = new Vector3(Input.GetAxis("Mouse X") * rotateSpeed, -Input.GetAxis("Mouse Y") *rotateSpeed, 0);
transform.eulerAngles += new Vector3(angle.y, angle.x, 0);
}
}



照準器で狙った位置にライフル弾を発射する