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 sassykorn · Mar 15, 2021 at 11:50 PM · colorcolorpicker

Help,How to fix this?

alt text

so my 3rd line goes off into the stratosphere and it's supposed to be on the right centre of the same distance, tried a buncha stuff, can't figure it out, pls help.

Code:

public class ColorPick : MonoBehaviour { public GameObject colorIndicatorInstance; public Color pickedColor = Color.red; Color pickedOne = Color.white; Color pickedTwo = Color.white; Color pickedThree = Color.white; Color pickedFour = Color.white; Texture2D texture; Texture2D texture2; Texture2D texture3; Texture2D texture4;

 bool mouseActive = false;

 private Vector2 mousePos;
 private Vector2 mousePosTwo;
   
 private Vector2 mousePosComp;
 private Vector2 mousePosCompTwo;
   
 private Camera camera;

 private GameObject colorIndicator1;
 private GameObject colorIndicator2;
 private GameObject colorIndicator3;
 private GameObject colorIndicator4;

 // Start is called before the first frame update
 void Start()
 {
     colorIndicator1 = Instantiate(colorIndicatorInstance, new Vector3(0, 0, -100), Quaternion.Euler(new Vector3(90, 0, 0)));
     colorIndicator2 = Instantiate(colorIndicatorInstance, new Vector3(0, 0, -100), Quaternion.Euler(new Vector3(90, 0, 0)));
     colorIndicator3 = Instantiate(colorIndicatorInstance, new Vector3(0, 0, -100), Quaternion.Euler(new Vector3(90, 0, 0)));
     colorIndicator4 = Instantiate(colorIndicatorInstance, new Vector3(0, 0, -100), Quaternion.Euler(new Vector3(90, 0, 0)));

     camera = this.GetComponent<Camera>();
     mousePos = mousePosComp = new Vector2(camera.pixelWidth / 2.0f, camera.pixelHeight / 2.0f);
     mousePosTwo = mousePosCompTwo = new Vector2(camera.pixelWidth / 2.0f, camera.pixelHeight / 2.0f);
     


     texture = new Texture2D(1, 1);
     texture.SetPixel(0, 0, pickedColor);
     texture.Apply();

     texture2 = new Texture2D(1, 1);
     texture2.SetPixel(0, 0, pickedColor);
     texture2.Apply();

     texture3 = new Texture2D(1, 1);
     texture3.SetPixel(0, 0, pickedColor);
     texture3.Apply();

     texture4 = new Texture2D(1, 1);
     texture4.SetPixel(0, 0, pickedColor);
     texture4.Apply();
 }

 private Color GetColorAtMousePos(Vector2 mousePos)
 {
     RaycastHit hit;
     Ray ray = camera.ScreenPointToRay(mousePos);
     Physics.Raycast(ray, out hit);
     Color c = Color.white;
     if (hit.collider)
     {
         Texture2D tex = (Texture2D)hit.collider.GetComponent<Renderer>().material.mainTexture; // Get texture of object under mouse pointer
         c = tex.GetPixelBilinear(hit.textureCoord2.x, hit.textureCoord2.y); // Get color from texture
         
     }

     return c;
 }
   

 void DrawLines(int mode)
 {

     if (mouseActive)
     {
         mousePos = Input.mousePosition;
         mousePosComp = new Vector2(camera.pixelWidth - mousePos.x, camera.pixelHeight - mousePos.y);
         mousePosTwo = Input.mousePosition;
         mousePosCompTwo = new Vector2(camera.pixelWidth + mousePosTwo.x, camera.pixelHeight - mousePos.y);




         pickedOne = GetColorAtMousePos(mousePos);
         pickedTwo = GetColorAtMousePos(mousePosComp);
         pickedThree = GetColorAtMousePos(mousePosCompTwo);
         pickedFour = GetColorAtMousePos(mousePosCompTwo);
     }

     Vector3 mousePos3 = camera.ScreenToWorldPoint(mousePos);
     Vector3 mousePos3Comp = camera.ScreenToWorldPoint(mousePosComp);
     Vector3 mousePos3Two = camera.ScreenToWorldPoint(mousePosTwo);
     Vector3 mousePos3TwoComp = camera.ScreenToWorldPoint(mousePosCompTwo);

     switch (mode)
     {
         
         default:
             //1
             Debug.DrawLine(new Vector3(0, 0, 0), mousePos3, Color.black);
             colorIndicator1.transform.position = mousePos3;
             colorIndicator1.GetComponent<MeshRenderer>().material.color = pickedOne;
             colorIndicator1.transform.GetChild(0).GetComponent<MeshRenderer>().material.color = Color.black;

             Debug.DrawLine(new Vector3(0, 0, 0), mousePos3Comp, Color.black);
             colorIndicator2.transform.position = mousePos3Comp;
             colorIndicator2.GetComponent<MeshRenderer>().material.color = pickedTwo;
             colorIndicator2.transform.GetChild(0).GetComponent<MeshRenderer>().material.color = Color.black;

             //2
             //Debug.DrawLine(new Vector3(0, 0, 0), mousePos3Two, Color.black);
             //colorIndicator3.transform.position = mousePos3Two;
             //colorIndicator3.GetComponent<MeshRenderer>().material.color = pickedThree;
             //colorIndicator3.transform.GetChild(0).GetComponent<MeshRenderer>().material.color = Color.black;

             Debug.DrawLine(new Vector3(0, 0, 0), mousePos3TwoComp, Color.black);
             colorIndicator3.transform.position = mousePos3TwoComp;
             colorIndicator3.GetComponent<MeshRenderer>().material.color = pickedThree;
             colorIndicator3.transform.GetChild(0).GetComponent<MeshRenderer>().material.color = Color.black;

             break;

         case 2:
             //2
             //Debug.DrawLine(new Vector3(0, 0, 0), mousePos3Two, Color.black);
             //colorIndicator3.transform.position = mousePos3Two;
             //colorIndicator3.GetComponent<MeshRenderer>().material.color = pickedThree;
             //colorIndicator3.transform.GetChild(0).GetComponent<MeshRenderer>().material.color = Color.black;

             //Debug.DrawLine(new Vector3(0, 0, 0), mousePos3TwoComp, Color.black);
             //colorIndicator3.transform.position = mousePos3TwoComp;
             //colorIndicator3.GetComponent<MeshRenderer>().material.color = pickedThree;
             //colorIndicator3.transform.GetChild(0).GetComponent<MeshRenderer>().material.color = Color.black;
             break;
     }
     
 }


 // Update is called once per frame
 void Update()
 {
     DrawLines(0);

     texture.SetPixel(0, 0, pickedOne);
     texture.Apply();

     texture2.SetPixel(0, 0, pickedTwo);
     texture2.Apply();

     texture3.SetPixel(0, 0, pickedThree);
     texture3.Apply();

     texture4.SetPixel(0, 0, pickedFour);
     texture4.Apply();
 }

 private void OnGUI()
 {

     if (Event.current.type == EventType.MouseDown)
     {
         mouseActive = !mouseActive;
     }

     GUI.skin.box.normal.background = texture;
     GUI.Box(new Rect(25,25, 75, 75),GUIContent.none);
     GUI.skin.box.normal.background = texture2;
     GUI.Box(new Rect(25,150, 75, 75),GUIContent.none);
     GUI.skin.box.normal.background = texture3;
     GUI.Box(new Rect(25,275, 75, 75), GUIContent.none);
     GUI.skin.box.normal.background = texture4;
     GUI.Box(new Rect(25, 400, 75, 75), GUIContent.none);
 }

}

this-bitch.png (189.5 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

113 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

Related Questions

Material doesn't have a color property '_Color' 4 Answers

Changing two different objects renderer colour 1 Answer

Creating differently colored cubes, selecting by pressing 1,2,3,... 2 Answers

Using Three sliders (RGB) to change the sea color 1 Answer

Runtime Equivelent of EditorGUIUtility.HSVToRGB() 3 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