Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • 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

avatar image
0
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
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jsundgren · Apr 28, 2017 at 01:26 PM 0
Share

Never$$anonymous$$d, I fixed it!

Had to define a material. :-)

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Call different geometry shader functions, for different primitive type: How? 1 Answer

Can we change the color on my Virtual Object on AR Foundation ?,Can we change color on AR Foundation with a button or touch ? 1 Answer

3 Color linear gradient shader 1 Answer

Changing the colour of my shaders through GUI Colour palette? 0 Answers

Change color of WaterPro (Standard Assets) when a Particle touch it,Particle Collision with Water and change Refraction Color 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges