Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am trying to make a terrain in Unity move, but im having trouble. Here's the code i have.

using UnityEngine;
using System.Collections;

public class NewScript : MonoBehaviour {

Camera camera;

Transform Terrain;
// Use this for initialization
void Start () {

}
// Update is called once per frame
void Update () {
    Terrain.Translate(new Vector3(500, 500 ,500));
}
}

now i would suspect that the terrain would just keep translating its position but it doesnt budge. How do i make a terrain move, or if you cant, how can i make the camera move and preferably with input. I am familiar with the XNA framework, is there a way to implement the input from XNA into unity?

share|improve this question
    
You tacked a question about input onto the end of this one, and it seems to be unrelated unless you expand the scope of your main question. –  michael.bartnett Mar 7 '13 at 22:34
    
I think the problem was that you forgot to attach the terrain object to the script, or you forgot to put the script in your scene. But actually this is not a good script design because you make no use of the object that this script is attached to, you only modify linked GameObject. You might want to look around for a good tutorial series to get yourself more acquainted with Unity. –  Benjamin Danger Johnson Mar 8 '13 at 0:40
add comment

1 Answer

up vote 4 down vote accepted

First (and I only say this because you are new to Unity), make sure you have the script attached to your Terrain GameObject (drag it from the project window and release it on top of the terrain GameObject in the Hierarchy). Then you can access the terrains transform in the script. Note that this will actually work for any GameObject including Prefabs, Cameras, and Terrain (try attaching the script to a Cube and point your Camera at it).

using UnityEngine;
using System.Collections;

public class AnyObjectMover : MonoBehaviour {
    // Use this for initialization
    void Start() { }

    // Update is called once per frame
    void Update() {
        // If you don't see this in update you did not attach your script.
        Debug.Log("moving object 5 units in every direction.");

        // transform = the transform of the object this script is applied to.
        transform.Translate(new Vector3(5, 5, 5));
    }
}
share|improve this answer
1  
Oh I forgot to mention this in my answer. if you want smooth translation, use something like "Vector3 speed = new Vector3(1, 0, 0); transform.Translate(speed * Time.deltaTime);" Time.deltaTime is the amount of time that has passed since your last update (where 1 = 1 second). This should make unit for your speed units per second. –  Benjamin Danger Johnson Mar 8 '13 at 0:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.