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 /
avatar image
0
Question by Grey_Wolf9 · Aug 12, 2018 at 03:29 AM · processingresponse

Arduino Unity processing

Hello all,

This question refers to the link below: https://freetronicsblog.wordpress.com/2012/09/06/experimenting-with-unity-processing-and-arduino/

How would I go about doing this? currently I have a cube that responds to a force sensor. The cube changes colour and texture according to the force exerted. How would I do something like in the link?

I have tried the code below but the cube just disappears when i press the force sensor: using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO.Ports; using UnityEngine.SceneManagement;

 public class Change_scale : MonoBehaviour
 {
     SerialPort stream = new SerialPort("\\\\.\\COM6", 9600);
     GameObject Cube;
     Material m_Material;
     private object go;
 
     // Renderer rend;
     void Awake()
 
     {
         stream.Open(); //Open the Serial Stream.
         stream.ReadTimeout = 10; //Give a Timeout to Serial Stream Reading
         Cube = GameObject.FindWithTag("Player");
         //m_Material = GameObject.FindWithTag("Player").GetComponent<Renderer>().material;
         // go = GameObject.FindWithTag("Player").GetComponent<Renderer>();
     }
 
     void Start()
     {
         GameObject go = GameObject.Find("Cube");
     }
     void Update()
     {
         try
 
         {
             string value = stream.ReadTo("EOL"); //Read the information
             float intensity = float.Parse(value);
             Debug.Log(intensity);
             if (intensity > 20)
             {
                 Cube.transform.localScale = new Vector3(intensity, 0f, 0f);
                // m_Material.color = Color.grey;
             }
             else
             {
                 Cube.transform.localScale = new Vector3(0f, 0f, 0f);
 
             }
 
             if (intensity > 26)
 
             {
                 Cube.transform.localScale = new Vector3(intensity, 0f, 0f);
                // m_Material.color = Color.blue;
             }
             else
             {
                 Cube.transform.localScale = new Vector3(0f, 0f, 0f);
 
             }
 
             stream.BaseStream.Flush(); //Clear the serial information so we assure we get new information.
         }
         catch (System.Exception e)
         {
             Debug.Log("Error: " + e);
         }
 
     }
 }
 

Can someone tell me how to fix this so that the cube in unity responds to the sensor by changing shape in the same manner that the real cube would (as in the video)?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Sep 19, 2018 at 11:28 PM

You set the scale to "0" which makes no sense. That would squish the cube to the size of 0. The default scale is "1,1,1". So instead of 0f,0f,0f you should use 1f,1f,1f and instead of intensity, 0f, 0f you should use intensity, 1f, 1f

Comment
Add comment · Show 1 · Share
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 Grey_Wolf9 · Sep 20, 2018 at 12:27 PM 0
Share

![alt text][1]

Thank you for your reply. I understand what you are saying and i have changed the code accordingly. However, now the cube stretches outwardly as depicted in the picture. Would i have to make the values 0.1 or something to get a reduction in the cube size? [1]: /storage/temp/124894-1.png

1.png (99.7 kB)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

88 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Handling Login Dialog Response on desktop 0 Answers

Making a process or functions high priority 0 Answers

WWW : Waiting for response from server 1 Answer

Do hidden (inactive?) objects take up processing time. 1 Answer

How to send Printer the screenshot from unity to print. (without closing or opening another application) 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