ジャンプ台(グラスホッパー)の作成
![368c008f e5be 42ef acb6 d4a1b5371b83](https://codegenius.org/uploads/slide/image/6598/368c008f-e5be-42ef-acb6-d4a1b5371b83.jpeg)
![A86eb6d2 46b7 424e bb35 72c781fcf50a](https://codegenius.org/uploads/slide/image/6599/a86eb6d2-46b7-424e-bb35-72c781fcf50a.jpeg)
![442b0d3c 6840 4930 8b6c 1cffa7d76146](https://codegenius.org/uploads/slide/image/6600/442b0d3c-6840-4930-8b6c-1cffa7d76146.jpeg)
![D3b9b4b6 f93e 4029 b90a a2482d243308](https://codegenius.org/uploads/slide/image/6601/d3b9b4b6-f93e-4029-b90a-a2482d243308.jpeg)
![E83ee539 6305 4da2 88e4 2a19bebd0134](https://codegenius.org/uploads/slide/image/6602/e83ee539-6305-4da2-88e4-2a19bebd0134.jpeg)
ジャンプ台の生成
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);
if(!controller.isGrounded)
{
if(Input.GetKeyDown(KeyCode.E))
{
StartCoroutine(ScaffoldManagement());
}
}
// ★追加
// GlassHopper(ジャンプ台)の生成
if(!controller.isGrounded)
{
if(Input.GetKeyDown(KeyCode.Q))
{
StartCoroutine(GlassHopperManagement());
}
}
}
}
private IEnumerator ScaffoldManagement()
{
GameObject scaffold = PhotonNetwork.Instantiate("Scaffold", genePoint.transform.position, Quaternion.identity);
yield return new WaitForSeconds(2f);
PhotonNetwork.Destroy(scaffold);
}
// ★追加
// GlassHopper
private IEnumerator GlassHopperManagement()
{
GameObject glassHopper = PhotonNetwork.Instantiate("GlassHopper", genePoint.transform.position, Quaternion.identity);
yield return new WaitForSeconds(2f);
PhotonNetwork.Destroy(glassHopper);
}
// ★追加
private void OnTriggerEnter(Collider other)
{
if(other.CompareTag("GlassHopper"))
{
moveDirection.y = 25f;
}
}
}
![Afe9ae12 56b3 4f3b 9a8f 2c8dda669065](https://codegenius.org/uploads/slide/image/6603/afe9ae12-56b3-4f3b-9a8f-2c8dda669065.jpeg)
![C1eb74e5 00fa 4dfe 827d 44f01c61e74e](https://codegenius.org/uploads/slide/image/6604/c1eb74e5-00fa-4dfe-827d-44f01c61e74e.jpeg)
【2020版】BattleOnline(基礎/全34回)
他のコースを見る![368c008f e5be 42ef acb6 d4a1b5371b83](https://codegenius.org/uploads/slide/image/6598/368c008f-e5be-42ef-acb6-d4a1b5371b83.jpeg)
![A86eb6d2 46b7 424e bb35 72c781fcf50a](https://codegenius.org/uploads/slide/image/6599/a86eb6d2-46b7-424e-bb35-72c781fcf50a.jpeg)
![442b0d3c 6840 4930 8b6c 1cffa7d76146](https://codegenius.org/uploads/slide/image/6600/442b0d3c-6840-4930-8b6c-1cffa7d76146.jpeg)
![D3b9b4b6 f93e 4029 b90a a2482d243308](https://codegenius.org/uploads/slide/image/6601/d3b9b4b6-f93e-4029-b90a-a2482d243308.jpeg)
![E83ee539 6305 4da2 88e4 2a19bebd0134](https://codegenius.org/uploads/slide/image/6602/e83ee539-6305-4da2-88e4-2a19bebd0134.jpeg)
ジャンプ台の生成
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);
if(!controller.isGrounded)
{
if(Input.GetKeyDown(KeyCode.E))
{
StartCoroutine(ScaffoldManagement());
}
}
// ★追加
// GlassHopper(ジャンプ台)の生成
if(!controller.isGrounded)
{
if(Input.GetKeyDown(KeyCode.Q))
{
StartCoroutine(GlassHopperManagement());
}
}
}
}
private IEnumerator ScaffoldManagement()
{
GameObject scaffold = PhotonNetwork.Instantiate("Scaffold", genePoint.transform.position, Quaternion.identity);
yield return new WaitForSeconds(2f);
PhotonNetwork.Destroy(scaffold);
}
// ★追加
// GlassHopper
private IEnumerator GlassHopperManagement()
{
GameObject glassHopper = PhotonNetwork.Instantiate("GlassHopper", genePoint.transform.position, Quaternion.identity);
yield return new WaitForSeconds(2f);
PhotonNetwork.Destroy(glassHopper);
}
// ★追加
private void OnTriggerEnter(Collider other)
{
if(other.CompareTag("GlassHopper"))
{
moveDirection.y = 25f;
}
}
}
![Afe9ae12 56b3 4f3b 9a8f 2c8dda669065](https://codegenius.org/uploads/slide/image/6603/afe9ae12-56b3-4f3b-9a8f-2c8dda669065.jpeg)
![C1eb74e5 00fa 4dfe 827d 44f01c61e74e](https://codegenius.org/uploads/slide/image/6604/c1eb74e5-00fa-4dfe-827d-44f01c61e74e.jpeg)
ジャンプ台(グラスホッパー)の作成