1

В Unity на сцене есть игровой объект - имитирующий зеркало. введите сюда описание изображения

Вот его код:

public class MirrorS : MonoBehaviour {
public Camera MCamera;
public int TextureSize = 500;
// Use this for initialization
void Start () {

}

// Update is called once per frame
void Awake()
{
    MCamera.targetTexture.width = TextureSize;
    MCamera.targetTexture.height = TextureSize;
}

private void OnBecameInvisible()
{
    MCamera.enabled = false;
}
private void OnBecameVisible()
{
    MCamera.enabled = true;
}

}

Если вкратце - мне необходимо создавать копии этого зеркала.

Примерно так:

 class ParticleData
{
  public  ParticleData(Vector3 position, float rotation )
    {


        Instantiate(InstObject, position, new Quaternion(rotation, rotation, rotation, rotation));

    }

}

Где InstObject - это ссылка на нужный объект.

 List<Particle> Particles = new List<Particle>(10);

Причем Экземпляры ParticleData создаю в цикле: - если нажата левая кнопка мыши и i=10 -т.е каждый десятый

for (int i = 0; i <= MainEmit.particleCount; i++)
        {
    if (i == Particles.ToArray().Length && Input.GetButton("Fire1")) 
            {
              P = new Particle();
                int EmitParticle = Particles.LastIndexOf( P, i);//10
                MainEmit.Emit(EmitParticle); //испускаем последнюю частицу из списка
                float ParticleLifeTime = Recalculate(P).GetEnumerator().Current;

                              data = new ParticleData(P.position = new Vector3(P.position.x + Particle_v + ParticleLifeTime, P.position.y + Particle_v + ParticleLifeTime, P.position.z + Particle_v + ParticleLifeTime), P.rotation);

            }

Но при создании копии этого объекта - происходит ошибка:

Setting width of already created render texture is not supported! UnityEngine.RenderTexture:set_width(Int32) MirrorS:Awake() (at Assets/MirrorS.cs:16) UnityEngine.Object:Instantiate(Object, Vector3, Quaternion) ParticleData:.ctor(Vector3, Single) (at Assets/particleSystemEmiter.cs:89) particleSystemEmiter:Update() (at Assets/particleSystemEmiter.cs:37)

Setting height of already created render texture is not supported! UnityEngine.RenderTexture:set_height(Int32) MirrorS:Awake() (at Assets/MirrorS.cs:17) UnityEngine.Object:Instantiate(Object, Vector3, Quaternion) ParticleData:.ctor(Vector3, Single) (at Assets/particleSystemEmiter.cs:89) particleSystemEmiter:Update() (at Assets/particleSystemEmiter.cs:37)

т.е оно как бы не может присвоить ту же ширину и высоту текстуры новосоздаваемому объекту?

Но ведь TextureSize - это можно сказать что "константа" при создании объекта? - как при следующем Instantiate - с ним могут возникать проблемы?

1 ответ 1

1

Для начала, для каждого зеркала нужна своя камера со своей renderTexture, а ты все в одной меняешь. Затем, если renderTexture уже создалась, то поменять ей размеры уже нельзя. Только сделав Release и new RenderTexture.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.