code ソーシャル

Unityアプリ作成(5)

スポンサーリンク

やっと本日のアプリ完成。誤植を見つけましたがなんとか解決できました。

プレイヤーの当たり判定の設定(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");
}
}

}

 

 

 

 

人気の記事

1

皆さん、ついに、エアラインでも、サブスクリプションが始まったのはご存じですか? まだ実験段階ですが、ANAが、定額全国住み放題サービスを提供する「ADDress」と組んで、国内線を4回まで定額利用可能 ...

2

無料でネットショップを開けるアプリとして多くの人に驚きを与えたBASE株式会社が、2019年10月25日東証マザーズに上場しました。2020年2月時点で90万店を超えるショップを抱えるまでに成長してい ...

3

2011年にサービスを開始してから圧倒的な成長率を誇るインテリア通販サイト 【FLYMEe/フライミー】を皆さんご存じでしょうか。 「自分のイメージするインテリア、本当に欲しいインテリアがどこにあるの ...

4

ついに、noteの月間アクティブユーザー数が4400万人(2020年3月時点)に到達しました。 そもそも、「note」とは、クリエイターが、文章やマンガ、写真、音声を投稿することができ、ユーザーはその ...

5

ボードゲームカフェが1日2回転で儲かるという記事をみつけたので興味を持ち、調べてみました。 まずは、需要がどれくらいあるのか、市場のようすからみていきましょう。 世界最大のボードゲーム市場はドイツで、 ...

-code, ソーシャル
-,

Copyright© BUSINESS HUNTER , 2023 All Rights Reserved Powered by AFFINGER5.