- Home /
This question was
closed Apr 28, 2017 at 01:26 PM by
jsundgren for the following reason:
The question is answered, right answer was accepted
Question by
jsundgren · Apr 27, 2017 at 12:34 PM ·
shadercolor changeprimitives
Change color for primitive
Hey!
I'm making an application where I use Vuforia to place out spots on a plane onTouch. (It's the beginning for an application to steer an Sphero robot). I want to make the spots I place out green but somehow my code doesn't work and they are black (I've added a light source in the scene). It's just annoying because it's probably just some small error but I can't find it. Here's my onTouch function:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TouchInput : MonoBehaviour {
public Text vecText;
// Update is called once per frame
void Update ()
{
// Attach this script to a trackable object
// Create a plane that matches the target plane
Plane targetPlane = new Plane(transform.up, transform.position);
GameObject origo = GameObject.CreatePrimitive (PrimitiveType.Cylinder);
origo.transform.parent = transform;
origo.transform.localScale = new Vector3(0.1f, 0, 0.1f);
origo.transform.position = new Vector3(0, 2.72f, 0);
foreach (Touch touch in Input.touches)
{
if (touch.phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(touch.position);
float dist = 0.0f;
targetPlane.Raycast(ray, out dist);
Vector3 planePoint = ray.GetPoint(dist);
GameObject pos = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
// Trying to make the spots green here!
pos.GetComponent<Renderer>().material.color = new Color(0, 1.0f, 0, 1.0f);
pos.transform.parent = transform;
pos.transform.localScale = new Vector3(0.1f, 0, 0.1f);
pos.transform.position = planePoint;
float vX = planePoint.x;
float vY = planePoint.y;
float vZ = planePoint.z;
vecText.text = "vX: " + vX.ToString() + "\n" +
"vY: " + vY.ToString() + "\n" +
"vZ: " + vZ.ToString ();
}
}
}
}
Can someone please point out my error?
Comment
Never$$anonymous$$d, I fixed it!
Had to define a material. :-)