足場(スキャホールド)の作成
足場(スキャホールド)の作成
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;
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);
// ★追加
// Scaffold(足場)の生成
if (!controller.isGrounded) // 条件は「空中」にいる時
{
if (Input.GetKeyDown(KeyCode.E))
{
StartCoroutine(ScaffoldManager());
}
}
}
}
// ★追加
private IEnumerator ScaffoldManager()
{
GameObject scaffold = PhotonNetwork.Instantiate("Scaffold", genePoint.transform.position, Quaternion.identity);
// 10秒後に消す(自由に変更可能)
yield return new WaitForSeconds(10f);
PhotonNetwork.Destroy(scaffold);
}
}
【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;
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);
// ★追加
// Scaffold(足場)の生成
if (!controller.isGrounded) // 条件は「空中」にいる時
{
if (Input.GetKeyDown(KeyCode.E))
{
StartCoroutine(ScaffoldManager());
}
}
}
}
// ★追加
private IEnumerator ScaffoldManager()
{
GameObject scaffold = PhotonNetwork.Instantiate("Scaffold", genePoint.transform.position, Quaternion.identity);
// 10秒後に消す(自由に変更可能)
yield return new WaitForSeconds(10f);
PhotonNetwork.Destroy(scaffold);
}
}
足場(スキャホールド)の作成