0

私の2Dゲーム内では、ユーザーが選択できるように多数のOnGui要素を用意したいと考えていますが、使用しているカーソルは別のongui要素です(kinectを使用してナビゲートします)。しかし、私はカメラをズームインおよびズームアウトするので、基本的にそれらを画面に取り付ける必要があります。アイデア、提案、または回避策。これは現在私のカーソルです。

using UnityEngine;
using System;
using System.Collections;

public class PillarAgent : MonoBehaviour {

public SkeletonWrapper sw;
public Vector3 distance;

public float progress =0f;

public Texture2D cursor;
public Texture2D load;

public Camera mainCam;

public float startTime;
private int roundedRestSecounds;

// Use this for initialization

    float differencex = 0;
    float differencey = 0;

void Start () {

    distance =new Vector3(0f,0f,0f);

}
float translate(float value, float leftMin, float leftMax, 
        float rightMin,float rightMax)
{
    float leftSpan = leftMax - leftMin;
    float rightSpan= rightMax - rightMin;

    float valueScaled = (value-leftMin)/(leftSpan);
    return rightMin+(valueScaled * rightSpan);
}
// Update is called once per frame
void Update () {
    if (sw.pollSkeleton())
    {
        distance.x=sw.bonePos[0,0].x - sw.bonePos[0,7].x;//5 is left shoulder
        distance.y=sw.bonePos[0,0].y -sw.bonePos[0,7].y;


        differencex=translate(distance.x,.6f,0,0,Screen.width);
        differencey=translate(distance.y,-.5f,0,0,Screen.height);
        //Debug.Log();

        float width = sw.bonePos[0,5].x+ sw.bonePos[0,9].x;
        float height =sw.bonePos[0,4].y- sw.bonePos[0,0].y;
        float heightdiv= (height/2)+sw.bonePos[0,0].y;        
    }    
}

void OnGUI() {
    //left top width height
    Rect r = new Rect(differencex,differencey,80,50);

    GUI.Label(r,cursor);
    GUI.BeginGroup(new Rect(differencex,differencey+50,50*Mathf.Clamp01(progress),15));
    //Debug.Log(progress);
    GUI.DrawTexture(new Rect(0,0,50,50),load);
    GUI.EndGroup();

    transform.position =mainCam.ScreenToWorldPoint(new Vector3(differencex,Screen.height-differencey,50));

    //mainCam.fieldOfView()    
}

void OnCollisionStay(Collision Other)
{
    startTime+=Time.deltaTime;

    if(Other.gameObject.GetComponent(typeof(TextControl)))
    {
        roundedRestSecounds=Mathf.CeilToInt(Time.time);

        progress = Time.time *0.2f;

        CurrentState=true;
    }
    else if(Other.gameObject.tag==("Scalpal")){


        progress = startTime *0.5f;
        //scallpall activated
        //    
    }        
}

void OnCollisionExit(Collision Other){
    startTime =0f;
    progress =0f;        
}

public Boolean CurrentState{get;set;}
}

次のクラスは基本的にツールをピックアップするクラスです。現在、このコードは機能しません (理由はわかりません)。しかし、画面に表示されるいくつかのツールを選択して、それらを使用できるようにしたいのです。たとえば、ペイントブラシを手に取り、レンガのペイントを開始します。現時点では、飛行機にツールを置いていますが、カメラが動いているときはいつでもツールを画面に表示したいと考えています。

using UnityEngine;
using System.Collections;

public class SelectTool : MonoBehaviour {

public Tools tools;
public float startTime;
public bool ScalpalSelected;
public GameObject selectedTool;

void Start()
{
    tools = this.GetComponent<Tools>(); //in order to use this tools muyst be attached to the game object
    //this is essentially saying  with regards to this game object get the component named tools
}
void update()
{

}
void OnCollisionStay(Collision Other)
{
    startTime +=Time.deltaTime;

    if(startTime >5f){
        if(Other.collider.tag==("Scalpal"))
        {
            selectedTool = Other.collider.gameObject;
            Debug.Log(selectedTool+" What in gods good name is:" +tools.utilities[0]);

        }
        else {
            selectedTool=null;
        }
        if(selectedTool){
            for(int i=0;i<tools.utilities.Length;i++)
            {

            }    
        }


            ScalpalSelected=true;
            renderer.material.color = Color.yellow;    
    }
}
void OncollisionStay(Collision other){

    startTime = 0f;
}

}
4

1 に答える 1