Exemple #1
0
 public void Action()
 {
     if (!linkedObjet)
     {
         InteractiveObject   tempObj = null;
         InteractiveObject[] intObjs = FindObjectsOfType(typeof(InteractiveObject)) as InteractiveObject[];
         float minDist = 999999f;
         foreach (InteractiveObject intObj in intObjs)
         {
             float dist = (intObj.transform.position - transform.position).magnitude;
             if (dist < minDist)
             {
                 minDist = dist;
                 tempObj = intObj;
             }
         }
         if (minDist <= actionRadius && tempObj)
         {
             int result = tempObj.Action();
             //if -1 play NO!! sound????
             if (result == 0)                   //Start pick animation
             {
                 linkedObjet = tempObj;
                 Vector3 tempScale = linkedObjet.transform.lossyScale;
                 if (HandSocket)
                 {
                     linkedObjet.transform.SetParent(HandSocket.transform);
                 }
                 else
                 {
                     linkedObjet.transform.SetParent(transform);
                 }
                 linkedObjet.transform.localPosition = new Vector3(0, 0, linkedObjet.transform.localPosition.z);
                 linkedObjet.transform.localScale    = new Vector3((1 / transform.lossyScale.x) * tempScale.x, (1 / transform.lossyScale.y) * tempScale.y, (1 / transform.lossyScale.z) * tempScale.z);
                 linkedObjet.transform.localRotation = Quaternion.identity;
                 onceActon         = false;
                 armTargetRotation = 90;
             }
             else if (result == 1)
             {
                 onceActon         = true;
                 armTargetRotation = 90;                    //Use animation???
             }
         }
     }
     else
     {
         int result = linkedObjet.Action();
         //if -1 play NO!! sound????
         //else use animation???
     }
 }
    protected virtual void Interact(RaycastHit hit)
    {
        InteractiveObject objScript = hit.transform.GetComponent <InteractiveObject>();

        if (objScript == null)
        {
            return;
        }
        else
        {
            objScript.Action(this);
        }
    }