Создать в среде Unity на языке C# скрипт, меняющий цвет объекта при щелчке по нему курсором мыши.
Поможем в ✍️ написании учебной работы
Поможем с курсовой, контрольной, дипломной, рефератом, отчетом по практике, научно-исследовательской и любой другой работой

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.EventSystems;

 

public class z6 : MonoBehaviour, IPointerClickHandler

{

/* Добавляем к мэйн камере PhysicRaycaster ,далее IZerarchy->пкм->UI-> EventSystem и в коде дописать библиотекуusing UnityEngine.EventSystems;

и MonoBehaviour, IPointerClickHandler

СКРИПТ НА ОБЪЕКТЕ */

// Start is called before the first frame update

public void OnPointerClick (PointerEventData eventData){

 

   StartCoroutine(SphereIndicator());

 

}

   

IEnumerator SphereIndicator () {

 

gameObject.GetComponent<Renderer>().material.color= Color.yellow;

yield return new WaitForSeconds(5f);

gameObject.GetComponent<Renderer>().material.color= Color.red;

 

}

}

 

Безкорутины


using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.EventSystems;

 

public class z7 : MonoBehaviour, IPointerClickHandler

{

/* Добавляем к мэйн камере PhysicRaycaster , IZerarchy->пкм->UI-> EventSystem и в коде дописать библиотеку и MonoBehaviour, IPointerClickHandler

СКРИПТ НА ОБЪЕКТЕ */

// Start is called before the first frame update

public void OnPointerClick (PointerEventData eventData){

 

   gameObject.GetComponent<Renderer>().material.color= Color.yellow;

 

}

   

  

}


Создать в среде Unity на языке C# скрипт, меняющий текстуру объекта при щелчке по нему курсором мыши.

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.EventSystems;

 

public class z7 : MonoBehaviour, IPointerClickHandler

{

  public Texture myTexture;

  

/* Добавляем к мэйн камере PhysicRaycaster , IZerarchy->пкм->UI-> EventSystem и в коде дописать библиотеку и MonoBehaviour, IPointerClickHandler

СКРИПТ НА ОБЪЕКТЕ

НЕОБХОДИМО СОЗДАТЬ МАТЕРИАЛ ОБЪЕКТА ДО (НЕ ОБЯЗАТЕЛЬНО)

    public Texture myTexture; ССЫЛОЧНАЯ ПЕРЕМЕННАЯ НА ТЕКСТУРУ

    ВЫБРАТЬ ЕЕ В ИНСПЕКТОРЕ */

 

public void OnPointerClick (PointerEventData eventData){

 

 

   gameObject.GetComponent<Renderer>().material.mainTexture = myTexture;

 

}

   

  

}

Создать в среде Unity на языке C# скрипт, перемещающий объект вперед, назад и в стороны при нажатии на зарезервированные клавиши (WASD) на клавиатуре.

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

 

public class var2 : MonoBehaviour {

public float speed = 1f;

 

// Use this for initialization

void Start()

{

}

 

// Update is called once per frame

void Update()

{

   float h = Input.GetAxis("Horizontal");

   float v = Input.GetAxis("Vertical");

 

   Vector3 tempVect = new Vector3(h, v, 0);

   tempVect = tempVect.normalized * speed * Time.deltaTime;

   transform.position += tempVect;

}

}

Создать в среде Unity на языке C# скрипт, перемещающий объект вперед, назад и в стороны при нажатии на определенные пользователем клавиши на клавиатуре.

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

public class z8 : MonoBehaviour

{

 

   float stopf=50;

 

  void Update()

{

   if(Input.GetKey(KeyCode.W))

   {

       transform.position += transform.up/stopf;     

         /* transform.position += new Vector3(0.0f, 0.0f, 0.5f); если через вектор*/

    }

     if(Input.GetKey(KeyCode.S))

   {

       transform.position -= transform.up/stopf;     

    }

//----------------------------------------------

 

     if(Input.GetKey(KeyCode.D))

   {

       transform.position += transform.right/stopf;     

    }

     if(Input.GetKey(KeyCode.A))

   {

       transform.position -= transform.right/stopf;     

    }

 

//--------------------------------------------------------

     if(Input.GetKey(KeyCode.Q))

   {

       transform.position += transform.forward/stopf;     

    }

     if(Input.GetKey(KeyCode.E))

   {

       transform.position -= transform.forward/stopf;     

    }

 

 

}

}

Дата: 2019-07-24, просмотров: 287.