09 กันยายน 2559

Unity : 2D Game with Unity Part # 2




โค้ดคำสั่งของ  background.cs

using UnityEngine;
using System.Collections;

public class background : MonoBehaviour {

public float bgSpeed;
float bgPositionX;
float bg1PositionX;
// Use this for initialization

void Start () {
bgPositionX = transform.position.x;
bg1PositionX = GameObject.Find ("background_1").transform.position.x;
}

// Update is called once per frame
void Update () {
transform.position = new Vector3 (transform.position.x + bgSpeed, transform.position.y, transform.position.z);
if (transform.position.x < (bg1PositionX * -1f)) {
transform.position = new Vector3 (bg1PositionX, transform.position.y, transform.position.z);
}
}
}
โค้ดคำสั่งของ floor.cs

using UnityEngine;
using System.Collections;

public class floor : MonoBehaviour {
public float bgSpeed;
float bgPositionX;
float bg1PositionX;
// Use this for initialization
void Start () {
bgPositionX = transform.position.x;
bg1PositionX = GameObject.Find ("floor_1").transform.position.x;
}

// Update is called once per frame
void Update () {
transform.position = new Vector3 (transform.position.x + bgSpeed, transform.position.y, transform.position.z);
if (transform.position.x < (bg1PositionX * -1f)) {
transform.position = new Vector3 (bg1PositionX, transform.position.y, transform.position.z);
}
}
}

ไม่มีความคิดเห็น:

"I Believe in You"

Copyright(c) 2007 - 2022 by Kasem Kamolchaipisit.