Trying to get a relatively sized RenderBuffer without an active camera in Unity?

In addition to my previous question: -the Problem with Instantiate -th Unity? - I when you create a new object simulating a mirror of a specified class - faced with the problem that when such a "generating object on the fly" using the Instantiate - RenderTexture - in all the objects and therefore need a method to calculate the return for each created object a new texture - ie to generate the texture had been also "on the fly" in the class responsible for the object that I was going to proinstallirovan. Ie causing Instantate and passing as a parameter to create an instance of the class to create a "mirror" in the very class I had to use RenderTexture method.GetTemporary() - for calculating the required textures for rendering.

MCamera.targetTexture= RenderTexture.GetTemporary(System.Convert.ToInt32((RecalculateRenderTexture(Move.herTransorm.position)[0])),
 System.Convert.ToInt32((RecalculateRenderTexture(Move.herTransorm.position)[0])), 
 System.Convert.ToInt32((RecalculateRenderTexture(Move.herTransorm.position)[2])));

The argument for RenderTexture.GetTemporary
I'm passing the return value of my method
RecalculateRenderTexture(Move.herTransorm.position)[0])
- index [0],[1],[2] - since the method returns several values , and "multiple" return-in addition to yield -(I in this case does not fit)- so return an array.
That's something like this:
float[] return_Array = new float[3];

 return_Array[0] = whidth_Texture;
 return_Array[1] = heigth_Texture;
 return_Array[2] = dethBuffer;
 return return_Array;
- ie in the method is the calculation of the texture for instancename mirrors and then these data are returned and peredayutsya the argument for RenderTexture.GetTemporary
The problem: when I return from
RecalculateRenderTexture(Move.herTransorm.position)[2])
- index of 2, the value of RenderBuffer - which I have specified as int dethBuffer = 0; - ie, the idea is for each object will return its value - your 0 or any other number (I also tried).
I have the error:
rying to get a relatively sized RenderBuffer without an active camera
-ie, try to install RenderBuffer - without active camera.
But in this case, the class field of the camera is:
public class mirror : MonoBehaviour {
 public Camera MCamera;

I tied and created the texture, but the error remains
MCamera.targetTexture= RenderTexture.GetTemporary(System.Convert.ToInt32((RecalculateRenderTexture(Move.herTransorm.position)[0])),
 System.Convert.ToInt32((RecalculateRenderTexture(Move.herTransorm.position)[0])), 
 System.Convert.ToInt32((RecalculateRenderTexture(Move.herTransorm.position)[2])));

While on stage starts going on "bacchanalia" - when you create an object camera(by main I mean the one which is attached to the character) begins to "compete" with the camera you just created object every second alternately replacing each other- ie just created a camera with a render texture is not attached to the newly created object (of type - Cancas) - and trying rendered on top of the main camera.
And in addition cu all the above - here is the full code of the class is responsible for the mirror. Maybe it will make it easier to understand the problem.
public class mirror : MonoBehaviour {
 public Camera MCamera;


 // Use this for initialization
 void Start () {

}

 // Update is called once per frame
 void Awake()
{




}

 private void Update()
{
 int k = 0;
 MCamera.targetTexture= RenderTexture.GetTemporary(System.Convert.ToInt32((RecalculateRenderTexture(Move.herTransorm.position)[0])),
 System.Convert.ToInt32((RecalculateRenderTexture(Move.herTransorm.position)[0])), 
System.Convert.ToInt32((RecalculateRenderTexture(Move.herTransorm.position)[2])));
}

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

 public float[] RecalculateRenderTexture(Vector3 pos)

 { bool IsCos = true;
 float DeltaX = Move.herTransorm.position.x*Time.deltaTime - Move.herTransorm.position.x;
 float PersonHeight = Move.herTransorm.transform.lossyScale.y;
 LookFor_B Vector3 = new Vector3(Move.LOOK,0,0);
 float sinB=0;
 heigth_Texture float = 0;
 float angle_T=0;// tskay base angle
 float cosB = PersonHeight / DeltaX;
 float angle_Y = Mathf.Sin(cosB);// counting by theorem of sines
 // heigth_Texture / angle_Y == (PersonHeight / 2) / sinB;
 //heigth_Texture / angle_Y == 2/ PersonHeight*sinB
 heigth_Texture = 2 * angle_Y / PersonHeight * sinB;
 if (cosB==0)
{
 sinB = 1;
}
 else if(cosB == 0 && IsCos==true && sinB==1)

{
 sinB = PersonHeight / DeltaX;
 angle_T = Mathf.Cos(sinB);// take the cosine theorem 
 heigth_Texture = Mathf.Sqrt(Mathf.Pow(PersonHeight, 2) + Mathf.Pow(DeltaX, 2) - 2 * PersonHeight * DeltaX * angle_T);

}

 whidth_Texture int = 0;
 dethBuffer int = 0;

 // particleSystemEmiter.P.position
 float[] return_Array = new float[3];

 return_Array[0] = whidth_Texture;
 return_Array[1] = heigth_Texture;
 return_Array[2] = dethBuffer;
 return return_Array; 

}
}
June 10th 19 at 15:04
1 answer
June 10th 19 at 15:06
Solution
what's the hoopla is another question of course..you can have cameras for mirrors is also a tag is MainCamera??

and so you're kind of error speaks for itself..
Trying to get a relatively sized RenderBuffer without an active camera
private void OnBecameInvisible()
{
 MCamera.enabled = false;
 }

how do you make the camera inactive, and swears that it won't take a render texture from off camera

and so bonus, take a look here
https://msdn.microsoft.com/ru-ru/library/system.tu...
you to not array to return poidee more than amiss. and will not be these ugly
System.Convert.ToInt32((RecalculateRenderTexture(Move.herTransorm.position)[0])

and all because the word..what you do with the array of float if in fact all convert to int??

Yes, and you know that three times call the method??
float[] tempArray = RecalculateRenderTexture(Move.herTransorm.position);
Camera.targetTexture= RenderTexture.GetTemporary(
 System.Convert.ToInt32(tempArray [0])),
 System.Convert.ToInt32(tempArray [0])), 
 System.Convert.ToInt32(tempArray [2])));


At least for now. just for readability.
and so then you would have to make a hierarchy of the scene..so you can see what you have in the link
public Camera MCamera;

you may not mirror each camera did..and only one for all mirror...then what is the mirror outside the main rendering will be disabled because the link is shared.

anyway this SLR camera to see the settings. - earline.Fad commented on June 10th 19 at 15:09
Well, in order:
1) the piece responsible for OnBecameInvisible and OnBecameVisible - I sacramentoa is the problem not solved.
2)Thank You for the advice -
float[] tempArray = RecalculateRenderTexture(Move.herTransorm.position);
Camera.targetTexture= RenderTexture.GetTemporary(
 System.Convert.ToInt32(tempArray [0])),
 System.Convert.ToInt32(tempArray [0])), 
 System.Convert.ToInt32(tempArray [2])));

- understand what was wrong fixed.
3)
you can have cameras for mirrors is also a tag is MainCamera??
- not really - that camera and the object to Instantiate I get from the prefab, and the prefab contains as an object of type Canvas, I search for it on this basis:
InstObject = GameObject.FindObjectsOfTypeIncludingAssets(typeof(Canvas));

Here is the hierarchy of the prefab:
5a32e52d4f021535654062.jpeg
4) what about the fact that I have a link to a public Camera MCamera; - so :
float[] tempArray = RecalculateRenderTexture(Move.herTransorm.position);
 MCamera.targetTexture = RenderTexture.GetTemporary(
System.Convert.ToInt32(tempArray[0]),
 System.Convert.ToInt32(tempArray[0]), 
 System.Convert.ToInt32(tempArray[2]));
and in the editor I do is clearly not perday - raegan.Hue commented on June 10th 19 at 15:12
so. stop. only now I looked in the documentation.

you read what makes a RenderTexture.GetTemporary and camera.targetTexture ???

RenderTexture.GetTemporary - return of the buffer, what was otrisovannye on the screen.
camera.targetTexture - if we assign the render texture, the camera will not render on the screen, in.

and how you combined it all?? it also does not work properly

you would create each mirror from the code of the render texture. pressdate or her, depending on the distance later (so less to render), but it then. get first just work it all.
public class mirror : MonoBehaviour {
 public Camera MCamera;
 public RenderTexture textureForMirror ;

 // Use this for initialization
 void Start () {
 textureForMirror = new RenderTexture(256, 256, 16, RenderTextureFormat.ARGB32);
 textureForMirror .Create();
//created to mirror the texture we want to render
//adjust the sizes and stuff of that pattern..
 MCamera.targetTexture= textureForMirror ;
//appointed and the camera to rencredit in a new texture (each mirror will have its own camera and its own texture.

}


///and where there used this texture
render.material.mainTexture = textureForMirror ;
}

it's so conditional. the essence of just

well, again, in addition
InstObject = GameObject.FindObjectsOfTypeIncludingAssets(typeof(Canvas));
just a nightmare, slow and outdated method.
than you just link to the prefab is put in the editor is not pleased?? what is a perversion? - earline.Fad commented on June 10th 19 at 15:15
Thank you! Tomorrow I'm going to fix it. Just one question : how to make a reference to the prefab in the editor? - raegan.Hue commented on June 10th 19 at 15:18
Um..
let's probably so..
https://unity3d.com/ru/learn/tutorials/topics/inte...
the General principles of what it is and how to use it.. - earline.Fad commented on June 10th 19 at 15:21

Find more questions by tags Unity Game EngineC#