最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Problems with moving objects using a script - Stack Overflow

programmeradmin1浏览0评论

Welcome. I also created this script to move objects where I need them in the scene, but I have a small problem. If I add a single object in object to move, the object moves, but if I add two or more objects, it doesn't work anymore, the objects stay in place and I have to press the button twice to make the move work. I tried to add the respective child objects to a main object and it still does the same

using UnityEngine;
using System.Collections;

public class MoveObject : MonoBehaviour
{
    public GameObject[] objectsToMove; 
    public Vector3 targetPosition; 
    public Vector3 targetRotation; 
    public GameObject RaceScripts;
    public GameObject RaceCampaign;
    public GameObject Race;
    public GameObject RCCCanvas;
    
    public void MoveAndRotate()
    {
        foreach (GameObject obj in objectsToMove)
        {
            obj.transform.position = targetPosition;
            obj.transform.rotation = Quaternion.Euler(targetRotation);
        }

        StartCoroutine(ActivateRaceComponentsWithDelay(0.1f));
    }
    
    private IEnumerator ActivateRaceComponentsWithDelay(float delay)
    {
        yield return new WaitForSeconds(delay);
        ActivateRaceComponents();
    }
    
    private void ActivateRaceComponents()
    {
        RaceScripts.GetComponent<Timer>().enabled = true;
        RaceCampaign.SetActive(false);
        Race.SetActive(true);
        RCCCanvas.SetActive(true);
    }
}

Example of the problem (YouTube video)

发布评论

评论列表(0)

  1. 暂无评论