Hi,
I am learning Unity at the moment. I tried to create a slope and create some balls to fall on it and want to see them rolling, however I can’t seems to modify the tile’s transform, here’s my code :
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
public Transform stoneBall;
public Transform tile;
void Start () {
GameObject newObject = (GameObject)Instantiate (tile);
newObject.transform.position = new Vector3 (10, 15, 10);
newObject.transform.Rotate (20f,20f,20f);
}
void Update () {
int x,y,z;
x = Random.Range (-10, 10);
y = Random.Range (1, 10);
z = Random.Range (-10, 10);
Instantiate(stoneBall, new Vector3 (x, y, z), Quaternion.identity);
}
}
These two lines doesn’t seems to work, if I modify the Prefab’s transform rotation through inspector, then i can’t see the balls rolling after it land on the tile slope, but I can’t seems to make it work using code.
I feel like I missed something very basic?? Thanks.
I can create the slope by using the following code instead, but not using Instantiate :
// tile
GameObject tile2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
tile2.transform.position = new Vector3(0, -3, 0);
tile2.transform.localScale += new Vector3(20, -0.1f, 10);
tile2.transform.Rotate(new Vector3(0, 0, 20));
Regards,
Alex