当前位置:网站首页>Circular sliding auto adsorption UI tool that monkeys can use
Circular sliding auto adsorption UI tool that monkeys can use
2022-06-28 03:35:00 【Starve fish】
The two script
Just mount one of them , Another auto mount
Script A
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Circle : MonoBehaviour
{
/*
* This script is divided into two parts
* The first part Circle, It is recommended to mount on the parent object of all objects to be moved
* then , Add all moving objects to go Array
* If you want to achieve adsorption , You need to add... For all sub objects Trigger and rigidbody And add the target substance to the adsorbed object ( It is suggested that the collision body be made smaller , More accurate )
*
* The second part adsorbent, Responsible for the adsorption of sub objects
* This script will be automatically responsible for mounting
* If an error is reported , If null reference . You don't need the adsorption function. You can choose to comment out
*/
[Header(" Rotation speed ")] public float speed = 0.2f;
[Header(" The object to be moved "), SerializeField]
public GameObject[] go;
// notes : If the major and minor axes are equal , Then the circle moves , Otherwise the ellipse
[Header(" The long axis is long "), SerializeField]
private float Ellipse_a;
[Header(" Short shaft length "), SerializeField]
private float Ellipse_b;
[Header(" The gap "), SerializeField,Range(0,1f)]
public float AwakeAngle = 60f;
[Header(" origin "), SerializeField]
private GameObject Point;
[Header(" Adsorbed reference "), SerializeField]
private GameObject AdsGameObject;
[Header(" Adsorption reference angle "), SerializeField, Range(0f, 360f)]
public float AdsAngle;
[Range(0.97f, 0.999f)]
[Header(" Degree of inertia reduction , The smaller, the faster ")] public float _inertiadown = 0.98f;
[Range(0f, 1f)]
[Header(" Inertia strength ")] public float _inertiastrong = 0.2f;
[Range(0f, 0.01f)]
[Header(" Adsorption strength . The higher the height, the faster the adsorption when the rotation stops ")] public float adstime = 0.01f;
/// <summary>
/// Call... In other scripts true All moving object positions will be reset
/// </summary>
public static bool ResetMove = true;
public void OnEnable()
{
adsorbent.adsa = AdsAngle;
int i = 0;
foreach (GameObject child in go)
{
child.AddComponent<adsorbent>();
child.GetComponent<adsorbent>().father = gameObject;
child.GetComponent<adsorbent>().AdsObj = AdsGameObject;
child.GetComponent<adsorbent>().id = i++;
}
AdsGameObject.transform.position = new Vector3(Ellipse_X(Ellipse_a, AdsAngle) + Point.transform.position.x, Ellipse_Y(Ellipse_b, AdsAngle) + Point.transform.position.y, 0);
}
private void Update()
{
MouseLister();
_memoryangle *= _inertiadown;
angle += _memoryangle * Time.deltaTime * _inertiastrong;
}
float _memoryangle;// Memorizing the angle difference creates inertia
public static float angle;
#region Elliptical route action
IEnumerator Move()
{
#if EditorMode
if (!Input.GetMouseButton(0))
{
yield return new WaitForSeconds(0.05f);
for (int i = 0; i < go.Length; i++)
go[i].transform.position = new Vector3(Ellipse_X(Ellipse_a, angle + 60 * i) + Point.transform.position.x, Ellipse_Y(Ellipse_b, angle + 60 * i) + Point.transform.position.y, 0);
ResetMove = false;
}
#else
yield return new WaitForSeconds(0.05f);
for (int i = 0; i < go.Length; i++)
go[i].transform.position = new Vector3(Ellipse_X(Ellipse_a, angle + AwakeAngle * i) + Point.transform.position.x, Ellipse_Y(Ellipse_b, angle + AwakeAngle * i) + Point.transform.position.y, 0);
ResetMove = false;
#endif
}
private float Ellipse_X(float a, float angle)
{
return a * Mathf.Cos(angle * Mathf.Rad2Deg);
}
private float Ellipse_Y(float b, float angle)
{
return b * Mathf.Sin(angle * Mathf.Rad2Deg);
}
#endregion
#region Mouse rotation
public void MouseLister()
{
if (Input.GetMouseButton(1) || ResetMove || Mathf.Abs(_memoryangle) > 0.002f)
StartCoroutine(Move());
if ((Input.GetMouseButton(0) || ResetMove || Mathf.Abs(_memoryangle) >= adstime))
{
adsorbent.ads = false;
StartCoroutine(Move());
if (Input.GetMouseButton(0))
{
_memoryangle += Input.GetAxis("Mouse X") * Time.deltaTime * speed;
angle += Input.GetAxis("Mouse X") * Time.deltaTime * speed;
}
}
else adsorbent.ads = true;
}
#endregion
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*
*
* Circle Script Affiliate script
* Do not mount manually
*
*
*
*
*/
public class adsorbent : MonoBehaviour
{
public void OnTriggerStay(Collider other)
{
if (ads && other.name == AdsObj.name)
Circle.angle =-(father.GetComponent<Circle>().AwakeAngle*id -adsa);
}
public int id;
public static float adsa;
[HideInInspector]
public GameObject father;
public static bool ads;
[HideInInspector]
public GameObject AdsObj;
}
Script reference :(73 Bar message ) unity Let the object move in a circle 、 Elliptical motion 、 Hyperbolic motion _ Small small feather, blog -CSDN Blog _unity Circular motion
边栏推荐
- A pit filling trip based on LNMP to build a personal website
- 17 `bs对象.节点名h3.parent` parents 获取父节点 祖先节点
- mysql获取当前时间是一年的第多少天
- 栈的基本操作(C语言实现)
- 数据库乱码问题
- Ten years' experience of Software Engineer
- Flow based depth generation model
- Severe Tire Damage:世界上第一个在互联网上直播的摇滚乐队
- 空闲中断无法清除
- What are the technologies to be mastered in the test? Database design for software testing
猜你喜欢
资源管理、高可用与自动化(下)
Dataloader参数collate_fn的使用
Is your IOT security strong enough?
Question bank and answers of special operation certificate for R1 quick opening pressure vessel operation in 2022
GAMES104 作业2-ColorGrading
基于 LNMP 搭建个人网站的填坑之旅
WPF 下的自定义控件以及 Grid 中控件的自适应
Object class, and__ new__,__ init__,__ setattr__,__ dict__
Redis搭建集群【简单】
Idea auto generate code
随机推荐
Notepad++--列编辑模式--用法/实例
基于 LNMP 搭建个人网站的填坑之旅
力扣每日一题-第29天-219.存在重复元素Ⅱ
新手开哪家的证券账户是比较好?股票开户安全吗
What is the best and safest software to download when buying stocks?
Custom controls under WPF and adaption of controls in Grid
17 `bs对象.节点名h3.parent` parents 获取父节点 祖先节点
大咖说·计算讲谈社|什么是东数西算要解决的核心问题?
2022 safety officer-c certificate examination question bank simulated examination platform operation
Excel知识技能汇总
[iptables & ICMP] description of ICMP Protocol in iptables default policy
matlab习题 —— 数据的基本处理
"9 No" principle and "5 measurement dimensions" of extensible system
The same is MB. Why is the gap so large?
Tardigrade: Trino's solution to ETL scenarios
新手开哪家的证券账户是比较好?炒股开户安全吗
数据库的迁移
【小程序】使用font-awesome字体图标的解决文案(图文)
2022危险化学品经营单位安全管理人员特种作业证考试题库模拟考试平台操作
Is your IOT security strong enough?