- Home /
Question by
techcrab · Mar 06, 2014 at 03:57 AM ·
c#instantiatescriptingbasics
How to create a Graph in Unity
Hi I'm trying to make a graphing calculator in Unity. I have it so that the code would instantiate an object throughout the course of the graph. I realize I could use a particle system to achieve the same effect but for this project I have to do this in this way or some similar form.
using UnityEngine;
using System.Collections;
public class Graph : MonoBehaviour
{
public Rigidbody GraphPointPrefab;
public int Resolution = 100;
private int i = -20;
private float Xposition = -20;
private float Yposition = 1;
void Update ()
{
while (i <= Resolution)
{
Yposition = 2 * Xposition +3;//equation
Instantiate (GraphPointPrefab, new Vector3 (Xposition, Yposition), Quaternion.Euler(0, 0, 0));
Xposition = + 1;
i ++;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
C# Instantiating a Gameobject with a Flat Sphere Collider 1 Answer
How do I stop Script from making multiple Cameras? 1 Answer
GameManager class doesn't accept GameObject.Find() 0 Answers
Script that switches between first and third person controller 3 Answers
Null Reference Exception on instantiated object's script. 2 Answers