Script error
Hello, I'm new to programming in C #, and I was trying to create a Flappy Bird type game, just to get used to a bit with C #, but whenever I do a script to make my scenario move gives some annoying error , That whenever I fix something happens in another error, I would be very happy if anyone could help me, sorry for my bad English, I am using google translator =)
My script
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class MoveOffset : MonoBehaviour {
private Material currentMaterial;
public float speed;
private float offset;
// Use this for initialization
void Start () {
currentMaterial = renderer.material;
}
// Update is called once per frame
void Update () {
offset += 0.001f;
currentMaterial.setTextureOffset ("_MainTex", new Vector2 (offset * speed, 0));
}
}
Answer by Pengocat · Dec 07, 2016 at 08:57 PM
You need to make sure that the gameobject the script is attached to has a Mesh-Renderer component with a material assigned and a Mesh-Filter with a mesh assigned.
Furthermore make sure the speed is set something other than 0 in the inspector for the texture to move.
The problem with the code is in line 9:
currentMaterial = gameObject.GetComponent<Renderer>().material;
Answer by tkamruzzaman · Dec 07, 2016 at 06:21 PM
use GetComponent<MeshRenderer>().material
instead of renderer.material and also SetTextureOffset
with capital 'S'
Your answer
Follow this Question
Related Questions
error CS0118 'charanim.CameraTurn' is a field but a 'type' was 'expected' 1 Answer
Unity 5.6 Update Exceptions 0 Answers
Why isnt the Unity tutorial working for me? 2 Answers
need help with errors,Need help with unity version and errors 1 Answer
Multiple errors after updating asset package from store 0 Answers