2017-08-24 150 views
0

你好我試圖使用滑塊像這樣顏色選擇器

enter image description here

精靈精靈將是顏色的預設選擇一種顏色,我不能在數學上生成精靈。 有什麼建議嗎?

回答

1

試試這個代碼從點擊位置的質感,並得到命中位置的像素顏色:

Vector2 pos = Input.mousePosition; 
Camera cam = Camera.mainCamera; 
Ray ray = cam.ScreenPointToRay(pos); 
Physics.Raycast(cam.transform.position, ray.direction, out hitPoint, 10000.0f); 
Color mycolor; 
if(hitPoint.collider) { 
    Texture2D tex = (Texture2D) hitPoint.collider.gameObject.renderer.material.mainTexture; 
    mycolor = tex.GetPixelBilinear(hitPoint.textureCoord2.x, hitPoint.textureCoord2.y); 
}