Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- By: Nathan Rumsey
- Engineer 3d llc
- 2022
- */
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class TransformThis : MonoBehaviour
- {
- public Transform transformThis;
- [Header("Transform")]
- public bool transformIO = false;
- public Vector3 transSpeed;
- [Header("Rotate")]
- public bool rotateIO = false;
- public Vector3 rotateSpeed;
- [Header("lookAt")]
- public bool lookAtIO = false;
- public Transform lookAtPoint;
- public bool lookAtInvertIO = false;
- [Header("Randome")]
- public bool randomeIO = false;
- public Transform randomlyMoveThis;
- public Vector2 MinMaxPositionX = new Vector2(-1,1);
- public Vector2 MinMaxPositionY = new Vector2(-1, 1);
- public Vector2 MinMaxPositionZ = new Vector2(-1, 1);
- public float movementIntervals = 1;
- [Header("PingPong"), Tooltip("requires parent maby")]
- public bool pingPongIO = false;
- Vector3 startPosition;
- Transform parentTransform;
- float realtime;
- // Start is called before the first frame update
- void Start()
- {
- if (pingPongIO) {
- if (transform.parent) {
- parentTransform = transform.parent;
- }
- startPosition = transform.position;
- }
- if (!transformThis)
- {
- transformThis = this.transform;
- }
- if (randomeIO) {
- StartCoroutine(randomeMove());
- }
- }
- // Update is called once per frame
- void Update()
- {
- realtime = Time.deltaTime;
- if (transformIO)
- transformThis.Translate(transSpeed.x * realtime, transSpeed.y * realtime, transSpeed.z * realtime);
- if (rotateIO)
- transformThis.Rotate(rotateSpeed.x * realtime, rotateSpeed.y * realtime, rotateSpeed.z * realtime);
- if (lookAtIO)
- if (lookAtInvertIO)
- {
- transformThis.rotation = Quaternion.LookRotation(lookAtPoint.position);
- }
- else
- {
- transformThis.LookAt(lookAtPoint);
- }
- if (pingPongIO ) {
- PingPongAction();
- }
- }
- IEnumerator randomeMove() {
- for (; ; ) {
- RandMove();
- yield return new WaitForSeconds(movementIntervals);
- }
- }
- public void RandMove() {
- randomlyMoveThis.position = new Vector3(
- this.transform.position.x + Random.Range(MinMaxPositionX.x, MinMaxPositionX.y),
- this.transform.position.y + Random.Range(MinMaxPositionY.x, MinMaxPositionY.y),
- this.transform.position.z + Random.Range(MinMaxPositionZ.x, MinMaxPositionZ.y));
- }
- void PingPongAction() {
- if (parentTransform)
- {
- transform.position = new Vector3(
- parentTransform.position.x,
- parentTransform.position.y + (Mathf.Sin(Time.time * 5) / 3),
- parentTransform.position.z);
- }
- else {
- transform.position = new Vector3(
- startPosition.x,
- startPosition.y + (Mathf.Sin(Time.time * 5) / 3),
- startPosition.z);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement