ジャンプ台(グラスホッパー)の作成
ジャンプ台で大ジャンプ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class PlayerController : MonoBehaviourPunCallbacks
{
public float speed = 6.0f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
private Vector3 moveDirection = Vector3.zero;
private CharacterController controller;
private Animator animator;
public GameObject genePoint;
// ★追加
private GameObject glassHopper;
void Start()
{
TryGetComponent(out controller);
animator = GetComponent<Animator>();
}
void Update()
{
if (photonView.IsMine)
{
if (controller.isGrounded)
{
var h = Input.GetAxis("Horizontal");
var v = Input.GetAxis("Vertical");
moveDirection = new Vector3(h, 0, v).normalized;
animator.SetFloat("Front", moveDirection.z, 0.1f, Time.deltaTime);
animator.SetFloat("Side", moveDirection.x, 0.1f, Time.deltaTime);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection = moveDirection * speed;
if (Input.GetKeyDown(KeyCode.Space))
{
moveDirection.y = jumpSpeed;
}
}
moveDirection.y = moveDirection.y - (gravity * Time.deltaTime);
controller.Move(moveDirection * Time.deltaTime);
if (!controller.isGrounded) // 条件は「空中」にいる時
{
if (Input.GetKeyDown(KeyCode.E))
{
StartCoroutine(ScaffoldManager());
}
// ★追加
// GlassHopper(ジャンプ台)の生成
if(Input.GetKeyDown(KeyCode.Z))
{
StartCoroutine(GlassHopperManager());
}
}
}
}
private IEnumerator ScaffoldManager()
{
GameObject scaffold = PhotonNetwork.Instantiate("Scaffold", genePoint.transform.position, Quaternion.identity);
yield return new WaitForSeconds(10f);
PhotonNetwork.Destroy(scaffold);
}
// ★追加
private IEnumerator GlassHopperManager()
{
glassHopper = PhotonNetwork.Instantiate("GlassHopper", genePoint.transform.position, Quaternion.identity);
yield return new WaitForSeconds(2f);
if(glassHopper) // 即消しになっていない場合には、2秒後に消す。
{
PhotonNetwork.Destroy(glassHopper);
}
}
// ★追加
private void OnTriggerEnter(Collider other)
{
if(other.CompareTag("GlassHopper"))
{
moveDirection.y = 25f; // ジャンプ力(自由に変更可能)
PhotonNetwork.Destroy(glassHopper); // 使用した場合には、即消す。
}
}
}
【2021版】BattleOnline(全37回)
他のコースを見るジャンプ台で大ジャンプ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class PlayerController : MonoBehaviourPunCallbacks
{
public float speed = 6.0f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
private Vector3 moveDirection = Vector3.zero;
private CharacterController controller;
private Animator animator;
public GameObject genePoint;
// ★追加
private GameObject glassHopper;
void Start()
{
TryGetComponent(out controller);
animator = GetComponent<Animator>();
}
void Update()
{
if (photonView.IsMine)
{
if (controller.isGrounded)
{
var h = Input.GetAxis("Horizontal");
var v = Input.GetAxis("Vertical");
moveDirection = new Vector3(h, 0, v).normalized;
animator.SetFloat("Front", moveDirection.z, 0.1f, Time.deltaTime);
animator.SetFloat("Side", moveDirection.x, 0.1f, Time.deltaTime);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection = moveDirection * speed;
if (Input.GetKeyDown(KeyCode.Space))
{
moveDirection.y = jumpSpeed;
}
}
moveDirection.y = moveDirection.y - (gravity * Time.deltaTime);
controller.Move(moveDirection * Time.deltaTime);
if (!controller.isGrounded) // 条件は「空中」にいる時
{
if (Input.GetKeyDown(KeyCode.E))
{
StartCoroutine(ScaffoldManager());
}
// ★追加
// GlassHopper(ジャンプ台)の生成
if(Input.GetKeyDown(KeyCode.Z))
{
StartCoroutine(GlassHopperManager());
}
}
}
}
private IEnumerator ScaffoldManager()
{
GameObject scaffold = PhotonNetwork.Instantiate("Scaffold", genePoint.transform.position, Quaternion.identity);
yield return new WaitForSeconds(10f);
PhotonNetwork.Destroy(scaffold);
}
// ★追加
private IEnumerator GlassHopperManager()
{
glassHopper = PhotonNetwork.Instantiate("GlassHopper", genePoint.transform.position, Quaternion.identity);
yield return new WaitForSeconds(2f);
if(glassHopper) // 即消しになっていない場合には、2秒後に消す。
{
PhotonNetwork.Destroy(glassHopper);
}
}
// ★追加
private void OnTriggerEnter(Collider other)
{
if(other.CompareTag("GlassHopper"))
{
moveDirection.y = 25f; // ジャンプ力(自由に変更可能)
PhotonNetwork.Destroy(glassHopper); // 使用した場合には、即消す。
}
}
}
ジャンプ台(グラスホッパー)の作成