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?

More than 3 years have passed since last update.

unity5.2の作法 その13 mouse

Posted at

概要

unity5.2の作法、調べてみた。
マウスで線をひく、やってみた。

makefile

  • menu->file->new sceneする。
  • menu->file->save sceneでsenとする。
  • menu->gameobject->create emptyする。
  • menu->assetes->creates->c# scriptでsen.csつくる。
  • ダブルクリックして、コードを書く。
  • ヒエラルキーのgameobjectに、コードを重ねる。
  • 三角で実行。

サンプルコード

using UnityEngine;
using System.Collections;

public class sen : MonoBehaviour {
    LineRenderer lr;
    int n;
	void Start () {
        lr = new GameObject().AddComponent<LineRenderer>();
        lr.SetColors(Color.red, Color.red);
        lr.useWorldSpace = true;
        lr.SetWidth(0.5f, 0.5f);
        n = 0;
	}
	void Update () {
        if (Input.GetMouseButtonDown(0))
        {
            lr.SetVertexCount(n + 1);
            Vector3 point = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            lr.SetPosition(n, new Vector3(point.x, point.y, 0f));
            n++;
            Debug.Log(n);
        }
        if (Input.GetMouseButtonUp(1))
        {
            lr.SetVertexCount(0);
            n = 0;
        }
	}
}




以上。

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?