BasicKnowledgeUnity/UnityProject/Assets/Scripts/Lesson_8.cs

47 lines
1020 B
C#
Raw Normal View History

2025-05-12 01:29:30 +03:00
/*
* Author: Nikolay Dvurechensky
* Site: https://www.dvurechensky.pro/
* Gmail: dvurechenskysoft@gmail.com
* Last Updated: 12 мая 2025 01:23:16
* Version: 1.0.3
*/
2024-10-05 08:54:55 +03:00
using UnityEngine;
using UnityEngine.UI;
/*
2025-05-12 01:29:30 +03:00
* События OnCollision и OnTrigger
* проявляющееся на объекте Cube
* после соприкосновения с Wall
* и GameObject.Find
2024-10-05 08:54:55 +03:00
*/
public class Lesson_8 : MonoBehaviour
{
public GameObject instObj;
private int count = 0;
[SerializeField]
private float speed = 4f;
private Text text;
private float ZPos = .0f;
private void Awake()
{
text = GameObject.Find("Text").GetComponent<Text>();
}
private void OnTriggerEnter(Collider other)
{
text.text = $"{other.gameObject.name} {count++}";
}
private void Update()
{
ZPos = Input.GetAxis("Vertical");
}
private void FixedUpdate()
{
instObj.transform.Translate(Vector3.forward * speed * ZPos);
}
}