라인이미지 그리기

UI의 이미지에 아래 스크립트를 추가하고 아래와 같이 수정하면 라인이 그려짐



using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class LineImage : MonoBehaviour {

    private RectTransform imageRectTransform;
    public float lineWidth = 1.0f;
    public Vector3 pointA;
    public Vector3 pointB;
    // Use this for initialization
    void Start () {
        imageRectTransform = GetComponent<RectTransform>();
    }
	
	// Update is called once per frame
	void Update () {
        Vector3 differenceVector = pointB - pointA;

        imageRectTransform.sizeDelta = new Vector2(differenceVector.magnitude, lineWidth);
        imageRectTransform.pivot = new Vector2(0, 0.5f);
        imageRectTransform.position = pointA;
        float angle = Mathf.Atan2(differenceVector.y, differenceVector.x) * Mathf.Rad2Deg;
        imageRectTransform.rotation = Quaternion.Euler(0, 0, angle);
    }
}



'Unity' 카테고리의 다른 글

unity - git사용시 설정  (0) 2016.01.11
스마트폰 해상도 정리  (0) 2016.01.11
플레이어의 Grid이동 효과  (0) 2016.01.03
플레이어 가속도 이동  (1) 2016.01.03
UNET 정리 1  (0) 2016.01.02
Posted by 빵원군
,