ReverseNormals
From Unify Community Wiki
(Difference between revisions)
m (Text replace - "</csharp>" to "</syntaxhighlight>") |
|||
(One intermediate revision by one user not shown) | |||
Line 10: | Line 10: | ||
==CSharp- ReverseNormals.cs== | ==CSharp- ReverseNormals.cs== | ||
− | <csharp> | + | <syntaxhighlight lang="csharp"> |
using UnityEngine; | using UnityEngine; | ||
using System.Collections; | using System.Collections; | ||
Line 42: | Line 42: | ||
} | } | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
Latest revision as of 20:45, 10 January 2012
Author: Joachim Ante
[edit] Description
This script lets you reverse normals. The normals will only be reversed in playmode so it will still look inverted when viewing in edit mode.
[edit] Usage
Attach the script to the mesh you want normals to be reversed
[edit] CSharp- ReverseNormals.cs
using UnityEngine; using System.Collections; [RequireComponent(typeof(MeshFilter))] public class ReverseNormals : MonoBehaviour { void Start () { MeshFilter filter = GetComponent(typeof (MeshFilter)) as MeshFilter; if (filter != null) { Mesh mesh = filter.mesh; Vector3[] normals = mesh.normals; for (int i=0;i<normals.Length;i++) normals[i] = -normals[i]; mesh.normals = normals; for (int m=0;m<mesh.subMeshCount;m++) { int[] triangles = mesh.GetTriangles(m); for (int i=0;i<triangles.Length;i+=3) { int temp = triangles[i + 0]; triangles[i + 0] = triangles[i + 1]; triangles[i + 1] = temp; } mesh.SetTriangles(triangles, m); } } } }