当前位置:网站首页>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
边栏推荐
- Tencent games released more than 40 products and projects, including 12 new games
- 华为设备WLAN基本业务配置命令
- 资源管理、高可用与自动化(中)
- MySQL 数据库的自动备份操作
- 力扣每日一题-第29天-575.分糖果
- service实现类里面为何一直报红
- kubernetes资源对象介绍及常用命令
- 2022 electrician (elementary) recurrent training question bank and online simulation examination
- 资源管理、高可用与自动化(下)
- 力扣每日一题-第29天-1491.去掉最低工资和最高工资后的平均工资
猜你喜欢
随机推荐
What is the core problem to be solved in the East and West?
Win10 如何删除系统盘大文件hiberfil.sys
idea自动生成代码
如何获取GC(垃圾回收器)的STW(暂停)时间?
s32ds跳转到DefaultISR
Relative path writing of files
项目实战!手把手教你 Jmeter 性能测试
同样是MB,差距怎么这么大呢?
Win 10出现bitlocke恢复,蓝屏错误代码0x1600007e
nn.Parameter和torch.nn.init系列函数给模型参数初始化
17 `bs对象.节点名h3.parent` parents 获取父节点 祖先节点
Import an excel file, solve the problem of skipping blank cells without reading and moving the subscript forward, and return_ BLANK_ AS_ Null red
PPT制作小技巧
自用工具 猴子都会用的unity视频播放器
MySQL错误
Arm development studio build compilation error
2022年R1快開門式壓力容器操作特種作業證考試題庫及答案
SSH框架的搭建(上)
No&nbsp;result&nbsp;defined&amp;nbsp…
Build your own website (17)









