- Home /
Can Someone Help Me With Changing Material / Texture On Collision Event
Hello, l have a problem getting my texture / material to apply when a collision event happens. I am not sure why this is not working. My C# Script is below, thank you for any help:
using UnityEngine;
using System.Collections;
public class CubeCollision : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter (Collision cul)
{
if (cul.gameObject.name == "PlayerCube")
GetComponent<Renderer>().material.mainTexture = ColourRed;
}
}
you should mark this as answered so it doesnt show up in the unanswered section
A good practice is to use [serializefeild] private Texture colorRed; It's still a private variable but you can assign it in the inspector as well as lower 'c' for vars because capitals are usually used for functions and methods. :)
Answer by CameronARP · Aug 18, 2015 at 06:03 AM
Sorry for wasting time, but l have done it now, however l can still share my fix, l just need to add this code at the top like so:
using UnityEngine;
using System.Collections;
public class CubeCollision : MonoBehaviour {
public Texture ColourRed;
Your answer
Follow this Question
Related Questions
Load Material to GameObject 2 Answers
How can I check if an instantiated object collides with another instantiated object? 1 Answer
Unity5.0 material not assigned on android 1 Answer
How to make the Health bar on Enemys head not be in relation to Player(main) Camera? 2 Answers
Scroll using material.mainTextureOffset makes the texture very distorted 1 Answer