Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 rbatelaan2 · Jul 30, 2020 at 07:38 PM · transparencyfor loopreading data

How do I make my for each loop go through all my points?

I have a code that spawns "pixels" at every position between 0 and 10 in the x, y, and z direction with a step of 0.4. I am trying to change the transparency of certain "pixels" based on a text file. When I run this file, only the last "point" has the correct transparency. Here is my code:

 using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 using UnityEngine;
 using System.IO;
 using System;
 using System.Runtime.InteropServices;
 
 public class FileManager : MonoBehaviour
 {
     public Renderer rend;
     float[] lines;
     string filePath, fileName;
 
     void Update()
     {
         if (Input.GetMouseButton(0))
         {
             fileName = "Wave_Time_3.txt";
             filePath = Application.dataPath + "/" + fileName;
             ReadFromTheFile();
         }
     }
 
     public class Point
     {
         public float x { get; set; }
         public float y { get; set; }
         public float z { get; set; }
         public float p { get; set; }
     }
 
     public void ReadFromTheFile()
     {
         List<Point> Points = new List<Point>();
         List<string> lines = File.ReadAllLines(filePath).ToList();
         foreach(var line in lines)
         {
             string[] entries = line.Split(',');
 
             Point newPoint = new Point();
 
             newPoint.x = float.Parse(entries[0]);
             newPoint.y = float.Parse(entries[1]);
             newPoint.z = float.Parse(entries[2]);
             newPoint.p = float.Parse(entries[3]);
 
             Points.Add(newPoint);
         }
 
         Color color = this.GetComponent<MeshRenderer>().material.color;
         rend = GetComponent<Renderer>();
 
         foreach (var Point in Points)
         {
             if (transform.position == new Vector3(Point.x, Point.y, Point.z))
             {
                 rend.enabled = true;
                 color.a = Points[0].p;
                 this.GetComponent<MeshRenderer>().material.color = color;
             }
             else
             {
                 rend.enabled = false;
             }
         }
     }
 }

Here is the content of my text file:

 4.75 , 5.00 , 5.00 , 0.04361341
 5.00 , 4.75 , 5.00 , 0.04361341
 5.00 , 5.00 , 4.75 , 0.04361341
 5.00 , 5.00 , 5.00 , 0.99263654
 5.00 , 5.00 , 5.25 , 0.04361341
 5.00 , 5.25 , 5.00 , 0.04361341
 5.25 , 5.00 , 5.00 , 0.04361341
 

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 Deivore · Jul 30, 2020 at 11:01 PM

Is something meant to be moving the FileManager object around? If not, it looks like the if statement code will only be executed if the point happens to have the same location as the FileManager's transform, which is a potential problem.

Additionally, the MeshRenderer attached to the FileManager's object is having its material's color set to different values, each of which will override the previous color value: the material only has one color value at a time. It sounds like what you are looking for is a way to set the values of different pixels, which means you either need separate MeshRenderers on different objects for the different pixels, or you need to be drawing to some kind of dynamic texture.

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

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

132 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 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

Alpha Transparent Shader hides NGUI fonts 0 Answers

Transparent shader with depth writes 3 Answers

Unity making existing shader partially transparent 1 Answer

How to sort draw order on transparent character puppet. 0 Answers

Object transparency separate from shader? 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