Unity2

Last-modified: 2026-01-31 (土) 16:32:27

便利な機能

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class P1ハリネズミ : MonoBehaviour
{
bool 右キー, 左キー, 上キー, 下キー, スペースキー;float 左右キー, 上下キー;
float A, B, C, D, E; float X, Y, Z;
float デルタタイム;

void Start()
{

}

void Update()
{
シーン0();
}

void シーン0()
{
右キー = 左キー = 上キー = 下キー = スペースキー = false;

左右キー = Input.GetAxisRaw("Horizontal");
if (左右キー == 1) { 右キー = true; } else if (左右キー == -1) { 左キー = true; }

上下キー = Input.GetAxisRaw("Vertical");
if (上下キー == 1) { 上キー = true; } else if (上下キー == -1) { 下キー = true; }

if (Input.GetButtonDown("Jump")) { スペースキー = true; }
デルタタイム = Time.deltaTime;
}

}

便利な機能集

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class 〇 : MonoBehaviour
{

static public void 画像表示(GameObject A) { A.GetComponent<Renderer>().enabled = true; }
static public void 画像非表示(GameObject A) { A.GetComponent<Renderer>().enabled = false; }
static public void 画像移動(GameObject A, float B, float C) { A.GetComponent<Rigidbody2D>().velocity = new Vector2(B, C);}
static public void 力移動(GameObject A, float B, float C) { A.GetComponent<Rigidbody2D>().AddForce(new Vector2(B, C), ForceMode2D.Impulse); }
static public void 座標移動(GameObject A, float B, float C, float D=0) { A.transform.position = new Vector3(B, C, D); }
static public void テキスト表示(GameObject A, string B) { A.GetComponent<Text>().text = B; }

static public void 画像サイズ(GameObject A, float B, float C) { A.transform.localScale = new Vector2(B, C); }
static public void シーン移動(string A) { SceneManager.LoadScene(A); }

}