やっと本日のアプリ完成。誤植を見つけましたがなんとか解決できました。
プレイヤーの当たり判定の設定(collider)が、collider otherのときにクリアシーンに移行するとなっており、足場である雲にもcolliderが使われていたため、うまくゲームを進めることができませんでした。
collider targetでtarget変数をゴールの旗のタグのFinishに紐付けることでうまく解決できました。
当たり判定を組み込む際は慎重に対象を狭め、otherを使うことはなるべく避けないければいけないことがわかりました。
共同作業で他の人が、自分の知らない場所でcolliderを使用していることがあるとそこがバグの要因になるからです。
作業開始時にこれはリーダーから明示しといた方がいいことですね。
今回は、スマホの加速度センサーでキャラクターを動かすようにしたのでスマホの録画動画を掲載します。
ゲームですが私には難しすぎてクリアできませんでした。
//playercontroller
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerController : MonoBehaviour
{
Rigidbody2D rigid2D;
Animator animator;
float jumpForce = 680.0f;
float walkForce = 30.0f;
float maxWalkSpeed = 2.0f;
float threshold = 0.2f;
void Start()
{
this.rigid2D = GetComponent<Rigidbody2D>();
this.animator = GetComponent<Animator>();
}
void Update()
{
if (Input.GetMouseButtonDown(0) && this.rigid2D.velocity.y == 0)
{
this.rigid2D.AddForce(transform.up * this.jumpForce);
}
int key = 0;
if (Input.acceleration.x > this.threshold) key = 1;
if (Input.acceleration.x < -this.threshold) key = -1;
float speedx = Mathf.Abs(this.rigid2D.velocity.x);
if (speedx < this.maxWalkSpeed)
{
this.rigid2D.AddForce(transform.right * key * this.walkForce);
}
if (key != 0)
{
transform.localScale = new Vector3(key, 1, 1);
}
this.animator.speed = speedx / 2.0f;
if (transform.position.y < -10)
{
SceneManager.LoadScene("GameScene");
}
}
void OnTriggerEnter2D(Collider2D target)
{
if (target.tag == "Finish")
{
Debug.Log("ゴール");
SceneManager.LoadScene("ClearScene");
}
}
}
//cameracontroller
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
GameObject player;
void Start()
{
this.player=GameObject.Find("cat");
}
void Update()
{
Vector3 playerPos=this.player.transform.position;
transform.position=new Vector3(transform.position.x,playerPos.y,transform.position.z);
}
}
//cleardirector
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ClearDirector : MonoBehaviour
{
void Update()
{
if(Input.GetMouseButtonDown(0))
{
SceneManager.LoadScene("GameScene");
}
}
}