Unity 3d – Script Collection

Home  >>  Tutorials  >>  Unity 3d  >>  Unity 3d – Script Collection

Unity 3d – Script Collection

11
Jul,2018

0

Player Follow the Camera Script

using UnityEngine;
using System.Collections;

public class CompleteCameraController : MonoBehaviour {

    public GameObject player;       
//Public variable to store a reference to the player game object


    private Vector3 offset;       
  //Private variable to store the offset distance between the player and camera

    // Use this for initialization
    void Start () 
    {
        //Calculate and store the offset value by getting the distance between 
//the player's position and camera's position.
        offset = transform.position - player.transform.position;
    }
    
    // LateUpdate is called after Update each frame
    void LateUpdate () 
    {
        // Set the position of the camera's transform to be the same as the player's,
// but offset by the calculated offset distance.
        transform.position = player.transform.position + offset;
    }
}

Player Move/Transform (Left)

<
using UnityEngine;
using System.Collections;

public class obstacleMoves : MonoBehaviour {

public float obstaclemMoveSpeed=10.4f;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
transform.Translate (-Vector2.right*obstaclemMoveSpeed*Time.deltaTime);

}
}

Leave a Reply

Your email address will not be published. Required fields are marked *