当前位置:网站首页>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
边栏推荐
- TypeError:&nbsp;&#039;module&amp;#03…
- 【PaddleDetection】ModuleNotFoundError: No module named ‘paddle‘
- 数据库的迁移
- Apache - Introduction à Apache
- s32ds跳转到DefaultISR
- 猴子都会用的圆形滑动自动吸附UI工具
- 华为设备WLAN基本业务配置命令
- Floating point and complex type of go data type (4)
- What is the core problem to be solved in the East and West?
- 电子地图坐标系统研究整理
猜你喜欢
随机推荐
Go 數據類型篇(四)之浮點型與複數類型
nn. Parameter and torch nn. Init series of functions to initialize model parameters
JS clear the object and its value:
GAMES104 作业2-ColorGrading
A16z: metauniverse unlocks new opportunities in game infrastructure
数的每一位平方和
Is it safe to buy stocks and open an account through the account opening link of the broker manager? Want to open an account for stock trading
[iptables & ICMP] description of ICMP Protocol in iptables default policy
Importer un fichier Excel, résoudre le problème de sauter les cellules vides et de ne pas lire, et avancer l'indice, et retourner Blank As NULL Red
开口式霍尔电流传感器如何助力直流配电改造?
Is your IOT security strong enough?
【小程序】使用font-awesome字体图标的解决文案(图文)
MySQL 数据库的自动备份操作
同样是MB,差距怎么这么大呢?
17 `bs对象.节点名h3.parent` parents 获取父节点 祖先节点
Notepad++--常用的插件
2022 electrician (elementary) recurrent training question bank and online simulation examination
What is the best and safest software to download when buying stocks?
Establishment of SSH Framework (Part I)
idea自动生成代码









