Files
MI-38/Heli_with_panels/Assets/Scripts/UI/ClickGruzCube2.cs
2022-07-04 13:15:35 +03:00

212 lines
5.7 KiB
C#
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<<<<<<< HEAD
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ClickGruzCube2 : MonoBehaviour
{
[SerializeField]
private float z;
private Vector3 startpos, endpos;// = new Vector3(-5.4f, 2.5f, 1.5f);
private Coroutine coroutine, coroutine2;
float cameraMoveCurTime, cameraMoveMaxTime = 1f;
float scrollSpeed = 0.5f;
Renderer rend;
float eulerAngZ;
[HideInInspector] public Manager manager;
bool flag_rev;
public Texture2D SampleTexture;
public Texture2D NormalTexture;
private void Awake()
{
manager = GameObject.Find("Manager").GetComponent<Manager>();
endpos =new Vector3(-5.4f, 2.5f,z);
rend = GetComponent<Renderer>();
rend.enabled = false;
eulerAngZ = transform.localEulerAngles.z;
RotationArrow();
flag_rev = false;
}
void OnMouseEnter()
{
RotationArrow();
rend.enabled = true;
coroutine2 = StartCoroutine(GoToArrow());
}
void OnMouseExit()
{
rend.enabled = false;
if (coroutine2 != null) StopCoroutine(coroutine2);
}
private void OnMouseDown()
{
if (manager.viewmode == 1) return;
cameraMoveCurTime = 0;
startpos = Camera.main.transform.position;
coroutine = StartCoroutine(GoToCube());
}
IEnumerator GoToCube()
{
float d;
while (cameraMoveCurTime < cameraMoveMaxTime)
{
cameraMoveCurTime += Time.deltaTime;
d = cameraMoveCurTime / cameraMoveMaxTime;
Camera.main.transform.position = Vector3.Lerp(startpos, endpos, d);
yield return null;
}
}
void RotationArrow()
{
if (Camera.main.transform.localEulerAngles.y > -90 && Camera.main.transform.localEulerAngles.y < 90|| Camera.main.transform.localEulerAngles.y > 270)
{
flag_rev = true;
}
else
{
flag_rev = false;
}
}
IEnumerator GoToArrow()
{
while (rend.enabled)
{
float offset = -Time.time * scrollSpeed;
if (flag_rev)
{
rend.material.SetTexture("_MainTex", SampleTexture);
rend.material.SetTextureOffset("_MainTex", new Vector2(-offset, 0));
}
else
{
rend.material.SetTexture("_MainTex", NormalTexture);
rend.material.SetTextureOffset("_MainTex", new Vector2(offset, 0));
}
yield return null;
}
}
public void FixedUpdate()
{
if (Input.GetMouseButtonDown(0))
{
if (coroutine != null) StopCoroutine(coroutine);
}
}
=======
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ClickGruzCube2 : MonoBehaviour
{
[SerializeField]
private float z;
private Vector3 startpos, endpos;// = new Vector3(-5.4f, 2.5f, 1.5f);
private Coroutine coroutine, coroutine2;
float cameraMoveCurTime, cameraMoveMaxTime = 1f;
float scrollSpeed = 0.5f;
Renderer rend;
float eulerAngZ;
[HideInInspector] public Manager manager;
bool flag_rev;
public Texture2D SampleTexture;
public Texture2D NormalTexture;
private void Awake()
{
manager = GameObject.Find("Manager").GetComponent<Manager>();
endpos =new Vector3(-5.4f, 2.5f,z);
rend = GetComponent<Renderer>();
rend.enabled = false;
eulerAngZ = transform.localEulerAngles.z;
RotationArrow();
flag_rev = false;
}
void OnMouseEnter()
{
RotationArrow();
rend.enabled = true;
coroutine2 = StartCoroutine(GoToArrow());
}
void OnMouseExit()
{
rend.enabled = false;
if (coroutine2 != null) StopCoroutine(coroutine2);
}
private void OnMouseDown()
{
if (manager.viewmode == 1) return;
cameraMoveCurTime = 0;
startpos = Camera.main.transform.position;
coroutine = StartCoroutine(GoToCube());
}
IEnumerator GoToCube()
{
float d;
while (cameraMoveCurTime < cameraMoveMaxTime)
{
cameraMoveCurTime += Time.deltaTime;
d = cameraMoveCurTime / cameraMoveMaxTime;
Camera.main.transform.position = Vector3.Lerp(startpos, endpos, d);
yield return null;
}
}
void RotationArrow()
{
if (Camera.main.transform.localEulerAngles.y > -90 && Camera.main.transform.localEulerAngles.y < 90|| Camera.main.transform.localEulerAngles.y > 270)
{
flag_rev = true;
}
else
{
flag_rev = false;
}
}
IEnumerator GoToArrow()
{
while (rend.enabled)
{
float offset = -Time.time * scrollSpeed;
if (flag_rev)
{
rend.material.SetTexture("_MainTex", SampleTexture);
rend.material.SetTextureOffset("_MainTex", new Vector2(-offset, 0));
}
else
{
rend.material.SetTexture("_MainTex", NormalTexture);
rend.material.SetTextureOffset("_MainTex", new Vector2(offset, 0));
}
yield return null;
}
}
public void FixedUpdate()
{
if (Input.GetMouseButtonDown(0))
{
if (coroutine != null) StopCoroutine(coroutine);
}
}
>>>>>>> 3b1b9479a46e90d056b92897ea9f8422b25fc052
}