Скрипт менеджера:
Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AnomalyManager : MonoBehaviour
{
public FurnitureInteract[] furniture;
void Start()
{
StartCoroutine(Interact());
}
IEnumerator Interact()
{
Debug.Log("1");
int waitUntil = Random.Range(20, 60);
int rand = Random.Range(1, 10);
Debug.Log(rand);
yield return new WaitForSeconds(waitUntil);
furniture[rand].anomaly();
Debug.Log(furniture[rand]);
int waitAfter = Random.Range(5, 15);
yield return new WaitForSeconds(waitAfter);
furniture[rand].anomalyBack();
}
}
using System.Collections.Generic;
using UnityEngine;
public class AnomalyManager : MonoBehaviour
{
public FurnitureInteract[] furniture;
void Start()
{
StartCoroutine(Interact());
}
IEnumerator Interact()
{
Debug.Log("1");
int waitUntil = Random.Range(20, 60);
int rand = Random.Range(1, 10);
Debug.Log(rand);
yield return new WaitForSeconds(waitUntil);
furniture[rand].anomaly();
Debug.Log(furniture[rand]);
int waitAfter = Random.Range(5, 15);
yield return new WaitForSeconds(waitAfter);
furniture[rand].anomalyBack();
}
}
Скрипт объекта:
Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FurnitureInteract : MonoBehaviour
{
private Vector3 fromPosition;
private Vector3 toPosition;
public float speed;
public float posY;
private float progress;
private void Start()
{
fromPosition = transform.position;
toPosition = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y + posY, gameObject.transform.position.z);
}
public void anomaly()
{
progress += Time.deltaTime * speed;
transform.position = Vector3.Lerp(fromPosition, toPosition, progress);
}
public void anomalyBack()
{
progress += Time.deltaTime * speed;
transform.position = Vector3.Lerp(toPosition, fromPosition, progress);
}
}
using System.Collections.Generic;
using UnityEngine;
public class FurnitureInteract : MonoBehaviour
{
private Vector3 fromPosition;
private Vector3 toPosition;
public float speed;
public float posY;
private float progress;
private void Start()
{
fromPosition = transform.position;
toPosition = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y + posY, gameObject.transform.position.z);
}
public void anomaly()
{
progress += Time.deltaTime * speed;
transform.position = Vector3.Lerp(fromPosition, toPosition, progress);
}
public void anomalyBack()
{
progress += Time.deltaTime * speed;
transform.position = Vector3.Lerp(toPosition, fromPosition, progress);
}
}