I’m trying to call a function from another script into a main script but it doesn’t seem to work no matter what i try.
using UnityEngine;
using System.Collections;
public class testbackground : MonoBehaviour {
public int[] y;
public int[] x;
// Use this for initialization
public void Start () {
y[0] = 1;
y[1] = 2;
y[2] = 3;
x[0] = 1;
x[1] = 2;
x[2] = 3;
Cube();
}
public void Cube(){
GameObject cube1 = GameObject.CreatePrimitive (PrimitiveType.Cube);
cube1.renderer.material.mainTexture = Resources.Load<Texture2D>("00");
cube1.transform.position = new Vector3 (0.5f, 0, 0);
cube1.transform.localScale = new Vector3 (370f, 240f, 1f);
cube1.transform.Rotate(new Vector3(0f, 180f, 0f));
}
// Update is called once per frame
void Update () {
}
}
So in this script i want to call Start into this script:
using UnityEngine;
using System.Collections;
public class Main : MonoBehaviour {
public testbackground Tilemap;
void Start () {
Screen.showCursor = false;
Tilemap = gameObject.AddComponent ("testbackground") as testbackground;
Tilemap.Start();
}
// Update is called once per frame
void Update () {
}
}
but nothing happens on screen, the cube never gets created. but if i moved the Cube function into the main script it works when i call it.
PLs help, what am i doing wrong in calling the class from the other script ?