I've written this code for my game and what I want is to flip the normals on a texture in unity. I have a model and a texture and wish for the texture to be inside the sphere model and not on the outside. I want to create a 360 panoramic effect by moving the camera around the images inside the sphere on top of the flipped texture.
Now, when I first hit the play button, it works perfectly, but then, when I stop it and want to play again, I don't see the board and neither the surroundings.
It seems that it works every 2 times that I try to play. I'm kind of new at this, and I have no idea where my mistake is.
using UnityEngine;
using System.Collections;
public class InvertObjectNormals : MonoBehaviour
{
public GameObject SferaPanoramica;
void Awake()
{
InvertSphere();
}
void InvertSphere()
{
Vector3[] normals = SferaPanoramica.GetComponent<MeshFilter>().sharedMesh.normals;
for(int i = 0; i < normals.Length; i++)
{
normals[i] = -normals[i];
}
SferaPanoramica.GetComponent<MeshFilter>().sharedMesh.normals = normals;
int[] triangles = SferaPanoramica.GetComponent<MeshFilter>().sharedMesh.triangles;
for (int i = 0; i < triangles.Length; i+=3)
{
int t = triangles[i];
triangles[i] = triangles[i + 2];
triangles[i + 2] = t;
}
SferaPanoramica.GetComponent<MeshFilter>().sharedMesh.triangles= triangles;
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…