PowenKo, Unity, LineRenderer, draw line on the board

January 9, 2012   ·   0 Comments

Screen Shot 2012-01-09 at 1.31.53 AM

using UnityEngine;
using System.Collections;

public class DrawLineScript : MonoBehaviour {
    public Color c1 = Color.yellow;
    public Color c2 = Color.red;
	private ArrayList lstNumbers = new ArrayList();
	//var lineArray= new Array();
    public int lengthOfLineRenderer = 20;
    void Start() {
        LineRenderer lineRenderer = gameObject.AddComponent<LineRenderer>();
        lineRenderer.material = new Material(Shader.Find("Particles/Additive"));
        lineRenderer.SetColors(c1, c2);
        lineRenderer.SetWidth(0.02f, 0.02f);
        lineRenderer.SetVertexCount(lengthOfLineRenderer);
    }
    void Update() {
		 if(Input.GetMouseButton(0)){
		//	if ( iPhoneInput.GetTouch(0).phase == iPhoneTouchPhase.Moved) {
		
			
			
				Vector3 mousePos=Input.mousePosition; //iPhoneInput.GetTouch(0).deltaPosition;
				// lineArray.Push(touchDeltaPosition);
			
			   
			
			mousePos.z = 1f;
Vector3 worldPos = Camera.main.ScreenToWorldPoint(mousePos);
			 
			Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
          
//Vector3 worldPos = ray.
			
				lstNumbers.Add(worldPos);//452.35);
				
			
		}
		
				Drawline();
    }
	// -------------------------------------
    void Drawline() {		
        LineRenderer lineRenderer = GetComponent<LineRenderer>();		
		int t_len=lstNumbers.Count;
		
      if(t_len>0){
	  lineRenderer.SetVertexCount(t_len);//lengthOfLineRenderer);
		
			//lineRenderer.Size=t_len;
			for(int a=0;a<t_len;a++){	
				Vector3 t1=(Vector3)lstNumbers[a];
				//t1.z=0;
				lineRenderer.SetPosition(a,t1);
			}
			
			
      if(t_len>20){
			lstNumbers.RemoveAt(0);
			}
			
		}
		
		
		
	}
}


shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Unity3D4

Amazon

adsbygoogle

Recent Posts

Categories

Amazon