jueves, 29 de septiembre de 2022

demo 7 de western ;

 

Explicacion mas detallada de recogida de objetos con C# de unity;

 using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class creaenmano3 : MonoBehaviour
{
   

    public GameObject retra, pico;


    // private void Update()/////original
    //  {/////////////////original

    //  if (Input.GetKeyDown(KeyCode.Alpha1))/////original



    // {////original
    // hacha.SetActive(false);///original
    //   pico.SetActive(false);/////original
    //     }////original


    private void OnTriggerEnter(Collider other)/////imbento
    {
        if (other.tag == "Player")///////imbento
        {/////////////////////////////////////imbento





            //  if (Input.GetKeyDown(KeyCode.Alpha2))//////original
            {
                retra.SetActive(true);
                pico.SetActive(false);
            }
            //   if (Input.GetKeyDown(KeyCode.Alpha3))
            //   {
            //   hacha.SetActive(false);
            //   pico.SetActive(true);
        }
    }
}
// }///////////////////imbento




En esta imagen de arriba el cubo donde puse el script...

aqui con la flecha raton señalo el arma que tiene en un hueso de la mano el Player, esta desactivada, en las sucesivas imagenes se puede ver como la arrastro en la casilla que produce el script, y el script la activa cuando el player entra en la zona del cubo al igual que produce el texto del manejo de esta, funciona de la misma forma...

 

 using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class activatTexto : MonoBehaviour
{
    public GameObject texto;

    private void OnTriggerEnter (Collider other)
    {
      if(other.tag == "Player")
        {
            texto.SetActive(true);
              

        }
    }
    private void OnTriggerExit(Collider other)
    {
        if (other.tag == "Player")
        {
            texto.SetActive(false);


        }
    }
}

 

fijarse en el video y en las imagenes , 






en la imagen indico que hay que arrastrar con el raton el arma desactivada a la casilla producida por el script en C# que hace aparecer el arma en la mano del player, ......

utilizo tambien otro script que hace borrar la imagen del arma al tocarla el player y da la sensacion que la recoje....

 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class destruyemetraportag : MonoBehaviour
{
   



    //public AudioSource tickSource;


    void Start()
    {

        //tickSource = GetComponent<AudioSource> ();



    }

    void Update()
    {
    }

    void OnTriggerEnter(Collider other)
    {
        //if (other.gameObject.CompareTag ("avismo")){
        //if (other.gameObject.CompareTag ("ogri2")){
        if (other.gameObject.CompareTag("Player"))
        {
            //transform.Rotate (new Vector3 (0 * Time.deltaTime, 91, 90), Space.Self);

            //tickSource.Play ();
            Destroy(gameObject, 0.0f);


        }
    }

}

//}