UnityTest

 2025.01.05 unity  
 2024.12.22 unity  
 2024.12.22 unity  
 2024.12.22 unity  
 2024.12.22 未分類  

page.phpテンプレートを利用しています。

Accelerator


using UnityEngine;
public class Accelerator : MonoBehaviour
{
    float speed = 8.0f;
    float angularSpeed = 360.0f;
    void Update()
 {
    Vector3 dir = Vector3.zero;
    //   dir.x = Input.acceleration.x;
    //    dir.z = Input.acceleration.y;
    dir.x = Input.acceleration.x * -1;
    dir.z = Input.acceleration.y * -1;
     if (dir.sqrMagnitude > 1)
          dir.Normalize();
     dir *= Time.deltaTime;
    transform.Translate(dir * speed, Space.World);
    transform.Rotate(new Vector3(dir.z, 0, -dir.x) * angularSpeed, Space.World);
  }
}

TimeNow


using UnityEngine;
using UnityEngine.UI; //Textを使用する為追加。
using System; //DateTimeを使用する為追加。
public class Timetext : MonoBehaviour
{
 //テキストUIをドラッグ&ドロップ
 [SerializeField] Text DateTimeText;
//DateTimeを使うため変数を設定
DateTime TodayNow;
void Update()
{
 //時間を取得
 TodayNow = DateTime.Now;
//テキストUIに年・月・日・秒を表示させる
 // DateTimeText.text = TodayNow.Year.ToString() + "年 " + TodayNow.Month.ToString() + "月" + TodayNow.Day.ToString() + "日" + DateTime.Now.ToLongTimeString();
 DateTimeText.text =
 TodayNow.Year.ToString() + "/ " +
 TodayNow.Month.ToString() + "/" +
TodayNow.Day.ToString() + " " +
 DateTime.Now.ToLongTimeString();
 }
}

TouchZoom



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

public class TouchMove : MonoBehaviour
{
    public Vector2 startPos;
    public Vector2 mouseStartPos;
    float dist0 = 0f;
    float dist1 = 0f;
    float scale = 0f;
    float oldDist = 0f;//前回の2点間の距離
    float minRate = 0.3f;
    float maxRate = 3f;
    Vector2 v = Vector2.zero;

    void Update()
    {
        if (Input.touchCount >= 2)
        {
            Touch t1 = Input.GetTouch(0);
            Touch t2 = Input.GetTouch(1);
            if (t2.phase == TouchPhase.Began)
            {
                dist0 = Vector2.Distance(t1.position, t2.position);
                oldDist = dist0;
            }
            else if (t1.phase == TouchPhase.Moved && t2.phase == TouchPhase.Moved)
            {
                dist1 = Vector2.Distance(t1.position, t2.position);
                if (dist0 < 0.001f || dist1 < 0.001f)
                {
                    return;
                }
                else
                {
                    v = transform.localScale;
                    scale = v.x;
                    scale += (dist1 - oldDist) / 400f;
                    if (scale > maxRate) { scale = maxRate; }
                    if (scale < minRate) { scale = minRate; }
                    oldDist = dist1;
            }
        transform.localScale = new Vector3(scale, scale, scale);
            }
        }
    }
}

Hello world!

WordPress へようこそ。こちらは最初の投稿です。編集または削除し、コンテンツ作成を始めてください。

月別
固定ページ
サンプルページ