0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

自分用のUnity備忘録

Posted at

当たり判定はOnCollisionEnter関数で実現できる。

void OnCollisionEnter(Collision collision){
    Debug.Log("Hello, world!");
}

シーンの切り替えはSceneManager.LoadScene関数で実現できる。

using UnityEngine.SceneManagement;

SceneManager.LoadScene("hogeScene");

上と併せて衝突時にシーン切り替えをするようにするのであれば

using UnityEngine.SceneManagement;

void OnCollisionEnter(Collision collision){
    SceneManager.LoadScene("hogeScene");
}

で実現可能。

unityroomのランキング機能を使用するにはUnityroomApiClient.Instance.SendScore関数を使えば良い。ただし、Packages/Unityroom Client Library/Api/UnityroomApiClientをシーンに配置した上で、HMAC認証用キーを入力必要がある。また、これは標準装備されている機能ではないので、https://github.com/naichilab/unityroom-client-library からダウンロードする必要がある(MIT licenseらしい)。

using unityroom.Api;

UnityroomApiClient.Instance.SendScore(1, 100f, ScoreboardWriteMode.HighScoreDesc);

キーを押した離したの操作はInput.GetKeyInput.GetKeyDmwnInput.GetKeyUpで実現できる。

if(Input.GetKey(KeyCode.A))
    Debug.Log("hoge");

if(Input.GetKeyDown(KeyCode.A))
    Debug.Log("huga");

if(Input.GetKeyUp(KeyCode.A))
    Debug.Log("Wow!");

今までのものと併せれば

using UnityEngine.SceneManagement;
using unityroom.Api;

void Update(){
    if(Input.GetKeyDown(KeyCode.S))
        UnityroomApiClient.Instance.SendScore(1, 100f, ScoreboardWriteMode.HighScoreDesc);
    if(Input.GetKeyDown(KeyCode.Q))
        SceneManager.LoadScene("hogeScene");
}

特定の2つの当たり判定を無くすには

Physics2D.IgnoreCollision(hoge, huga, true);

とやれば良い。

多分まだまだ増える。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?