PowenKo, Unity , LineRenderer,LineRenderer math sin at the run time

January 9, 2012   ·   0 Comments

Screen Shot 2012-01-09 at 12.49.43 AM

using UnityEngine;
using System.Collections;

public class LineScript : MonoBehaviour {
    public Color c1 = Color.yellow;
    public Color c2 = Color.red;
    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.2F, 0.2F);
        lineRenderer.SetVertexCount(lengthOfLineRenderer);
    }
    void Update() {
        LineRenderer lineRenderer = GetComponent<LineRenderer>();
        int i = 0;
        while (i < lengthOfLineRenderer) {
            Vector3 pos = new Vector3(i * 0.5F-3, Mathf.Sin(i + Time.time), 0);
            lineRenderer.SetPosition(i, pos);
            i++;
        }
    }
}

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