141 lines
4.0 KiB
C#
141 lines
4.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class GiveLike : MonoBehaviour
|
|
{
|
|
public Button likeButton;
|
|
public GameObject uiElement;
|
|
public GameObject findGameObject;
|
|
public GameObject previousGameObject = null;
|
|
|
|
public bool isDown = false;
|
|
public bool isDown2 = false;
|
|
void Start()
|
|
{
|
|
uiElement.SetActive(false);
|
|
}
|
|
//Renderer myRenderer;
|
|
Material material;
|
|
RaycastHit hit;
|
|
private void Update()
|
|
{
|
|
Vector3 screenCenter = new Vector3(Screen.width / 2, Screen.height / 2, 0);
|
|
|
|
Ray ray = Camera.main.ScreenPointToRay(screenCenter);
|
|
|
|
Debug.DrawRay(ray.origin, ray.direction * 1000, Color.red);
|
|
|
|
if (Physics.Raycast(ray, out hit))
|
|
{
|
|
findGameObject = hit.collider.gameObject;
|
|
//ChangeMaterial(findGameObject, new Color(1f, 0.843f, 0f)); // 255, 215, 0 in RGB
|
|
//myRenderer = hit.collider.gameObject.GetComponent<Renderer>();
|
|
|
|
}
|
|
else
|
|
{
|
|
//ChangeMaterial(findGameObject, Color.red); // 红色
|
|
findGameObject = null;
|
|
}
|
|
|
|
if (isDown)
|
|
{
|
|
if (previousGameObject != null && previousGameObject != findGameObject)
|
|
{
|
|
if (previousGameObject.name.Contains("视频Plane"))
|
|
{
|
|
//ChangeMaterial(previousGameObject, Color.red); // 红色
|
|
}
|
|
else if(previousGameObject.name.Contains("广告Plane"))
|
|
{
|
|
//ChangeMaterial(previousGameObject, Color.blue);
|
|
}
|
|
|
|
//highlightUser.OffGameObject(previousGameObject);
|
|
}
|
|
|
|
if (findGameObject != null)
|
|
{
|
|
if (previousGameObject.name.Contains("视频Plane"))
|
|
{
|
|
//ChangeMaterial(previousGameObject, Color.red); // 红色
|
|
}
|
|
else if(previousGameObject.name.Contains("广告Plane"))
|
|
{
|
|
//ChangeMaterial(previousGameObject, Color.blue);
|
|
}
|
|
Debug.Log("111");
|
|
}
|
|
}
|
|
else if (isDown2)
|
|
{
|
|
if (previousGameObject != null && previousGameObject != findGameObject)
|
|
{
|
|
if (previousGameObject.name.Contains("视频Plane"))
|
|
{
|
|
//ChangeMaterial(previousGameObject, Color.red); // 红色
|
|
}
|
|
else if(previousGameObject.name.Contains("广告Plane"))
|
|
{
|
|
//ChangeMaterial(previousGameObject, Color.blue);
|
|
}
|
|
}
|
|
|
|
if (findGameObject != null)
|
|
{
|
|
//ChangeMaterial(findGameObject, new Color(1f, 0.843f, 0f));
|
|
//highlightUser.SetGameObject(findGameObject);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (previousGameObject != null)
|
|
{
|
|
//ChangeMaterial(previousGameObject, Color.red); // 红色
|
|
//highlightUser.OffGameObject(previousGameObject);
|
|
}
|
|
}
|
|
|
|
previousGameObject = findGameObject;
|
|
}
|
|
void ChangeMaterial(GameObject obj, Color color)
|
|
{
|
|
Renderer renderer = obj?.GetComponent<Renderer>();
|
|
if (renderer != null && renderer.material != null)
|
|
{
|
|
renderer.material.color = color;
|
|
}
|
|
}
|
|
Renderer currRenderer;
|
|
Color color;
|
|
public void OnPointerDown()
|
|
{
|
|
//highlightUser.SetGameObject(findGameObject);
|
|
isDown = true;
|
|
uiElement.SetActive(true);
|
|
}
|
|
|
|
|
|
public void OnPointerUp()
|
|
{
|
|
isDown = false;
|
|
//currRenderer.material.color = color;
|
|
//highlightUser.OffGameObject(findGameObject);
|
|
uiElement.SetActive(false);
|
|
//findGameObject = null;
|
|
//myRenderer = currRenderer;
|
|
}
|
|
public void OnPointerDown2()
|
|
{
|
|
isDown2 = true;
|
|
}
|
|
|
|
|
|
public void OnPointerUp2()
|
|
{
|
|
isDown2 = false;
|
|
}
|
|
} |