20 กันยายน 2559

Unity : 2D Game with Unity Part # 5




// โค้ดคำสั่ง Main_Controller.cs

using UnityEngine;
using System.Collections;

public class Man_Controller : MonoBehaviour {
public float speed;
float x, sx;
bool ks;
Animator am;
Rigidbody2D rb;

// Use this for initialization
void Start () {
am = GetComponent<Animator> ();
rb = GetComponent<Rigidbody2D> ();
sx = transform.localScale.x;
}

// Update is called once per frame
void Update () {
x = Input.GetAxis ("Horizontal");
am.SetFloat ("speed", Abs (x));


if (Input.GetButtonDown ("Jump")) {
am.SetBool ("jump", true);
rb.velocity = new Vector2 (rb.velocity.x, 5f);
}

rb.velocity = new Vector2 (x * speed, rb.velocity.y);

if (x > 0) {
transform.localScale = new Vector3 (sx, transform.localScale.y, transform.localScale.z);
}

if (x < 0) {
transform.localScale = new Vector3 (-sx, transform.localScale.y, transform.localScale.z);
}
}

void OnCollisionEnter2D(Collision2D coll) {
am.SetBool ("jump", false);
}
float Abs(float x) {
return x >= 0f ? x : -x;
}
}



// โค้ดคำสั่ง CameraFollow.cs
using UnityEngine;
using System.Collections;

public class CameraFollow : MonoBehaviour {
public Transform obj;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.position = new Vector3 (obj.position.x, transform.position.y, transform.position.z);
}
}

10 กันยายน 2559

Unity : 2D Game with Unity Part # 3



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

using UnityEngine;
using System.Collections;

public class volt_controler : MonoBehaviour {
    public float jumpSpeed;
    Rigidbody2D rb;
    // Use this for initialization
    void Start () {
        rb = GetComponent ();
    }
   
    // Update is called once per frame
    void Update () {
        if (Input.GetButtonDown ("Jump")) {
            rb.velocity = new Vector2 (rb.velocity.x, jumpSpeed);
        }
    }
}

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);
}
}
}

01 กันยายน 2559

Ubuntu : การติดตั้ง Software และการแก้ปัญหาต่างๆ บน Ubuntu

ติดตั้ง LAMPP (Apache, MariaDB and PHP)
ให้ทำการดาวน์โหลดโปรแกรมที่เว็บ
https://www.apachefriends.org/download.html
วิธีติดตั้ง
https://www.apachefriends.org/faq_linux.html

กำหนดให้ phpmyadmin สามารถเรียกได้จาก internet ภายนอก
ให้แก้ไขไฟล์ httpd-xampp.conf ซึ่งเก็บอยู่ที่ /opt/lampp/etc/extra โดยพิมพ์คำสั่ง
   sudo nano /opt/lampp/etc/extra/httpd-xampp.conf
จากนั้นแก้ไขตรงส่วนของ ตามตัวอย่างด้านล่าง

< Directory "/opt/lampp/phpmyadmin"   >

   AllowOverride AuthConfig Limit
    Order allow,deny
    Allow from all
    Require all granted
    ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
 
 <  Directory   > 
  
จากนั้นทำการ รีสตาร์ lampp ใหม่
    sudo /opt/lampp/lampp restart

    ให้ทดสอบเข้า  http://localhost/phpmyadmin
     *** หากเข้า phpmyadmin แล้วไม่ถาม user และ password แสดงว่ายังไม่ได้กำหนดรหัสผ่านที่ mySQL ให้กับ root ให้เข้าไปกำหนดใน phpmyadmin ในส่วนของ user accounts  กำหนดรหัสผ่านให้กับ root ทุกตัว
     จากนั้นเข้าไปแก้ไขไฟล์ config.inc.php ซึ่งเก็บอยู่ที่ /opt/lampp/phpmyadmin

     sudo nano /opt/lampp/phpmyadmin/config.inc.php

     ตรงส่วนของ Authentication type ให้ลบ ชื่อ user ออก และ password ออก ดังนี้

      /* Authentication type */
     $cfg['Servers'][$i]['auth_type'] = 'cookie';
     $cfg['Servers'][$i]['user'] = '';
     $cfg['Servers'][$i]['password'] = '';
     $cfg['Servers'][$i]['extension'] = 'mysqli';
     /* Server parameters */
     $cfg['Servers'][$i]['host'] = 'localhost';
     $cfg['Servers'][$i]['connect_type'] = 'tcp';
     $cfg['Servers'][$i]['compress'] = false;
     $cfg['Servers'][$i]['AllowNoPassword'] = false;


วิธีติดตั้ง เว็บไทย
http://www.amplysoft.com/knowledge/install-apache2-php5-mysql-phpmyadmin-ubuntu.html

การจัดการ Service
ก่อนอื่นเปิดสถานะไฟล์ให้เรียกใช้งานได้ ทำแค่ครั้งแรกครั้งเดียว
cd /opt/lampp
sudo chmod 755 manager-linux-x64.run    (manager-linux.run สำหรับ 32บิต)
เวลาเรียกใช้งานพิมพ์คำสั่ง
sudo /opt/lampp/manager-linux-x64.run

กรณีที่เปิดเครื่องมาแล้ว เซอร์วิสของ lampp ไม่สตาร์ท ให้แก้ไขโดยใช้คำสั่ง
    sudo ln -s /opt/lampp/lampp  /etc/init.d/lampp
    sudo update-rc.d lampp start 80 2 3 4 5 . stop 30 0 1 6 .

ติดตั้ง Flash Player
  sudo apt-get update
  sudo apt-get install flashplugin-installer

การกำหนด Virtual Host

  ให้ทำการเปิด Terminal (Ctrl + Alt + T)
  จากนั้น เข้าไปแก้ไขไฟล์ httpd.conf ที่เก็บอยู่ภายใต้ /opt/lampp/etc โดยพิมพ์คำสั่งเปิดไฟล์ดังนี้

        sudo nano /opt/lampp/etc/httpd.conf

        ให้นำเครื่องหมาย # ออกให้เหลือแต่คำสั่ง ดังนี้ 
        Include etc/extra/httpd-vhosts.conf

   จากนั้น เข้าไปแก้ไขไฟล์ httpd-vhosts.conf ที่เก็บอยู่ภายใต้ /opt/lampp/etc/extra
        sudo nano /opt/lampp/etc/extra/httpd-vhosts.conf

    หากต้องการกำหนดให้ virtual host ชื่อ myweb โดยเก็บไฟล์ไว้ที่ /opt/lampp/apps/myweb/htdocs ให้เพิ่มคำสั่งดังนี้
  
   < virtualhost >
       DocumentRoot "/opt/lampp/htdocs/"
       ServerName localhost
   &lt/ virtualhost >
   < virtualhost >
       DocumentRoot "/opt/lampp/apps/myweb/htdocs"
       ServerName myweb.localhost
   </ virtualhost >
 
ติดตั้ง SAMBA ทำ file sharing ดูที่
http://na5cent.blogspot.com/2012/04/samba-ubutntu-1110-server.html

https://help.ubuntu.com/community/How%20to%20Create%20a%20Network%20Share%20Via%20Samba%20Via%20CLI%20(Command-line%20interface/Linux%20Terminal)%20-%20Uncomplicated,%20Simple%20and%20Brief%20Way!

ติดตั้ง MonoDeveloper ทำให้ linux รัน asp.net c# ได้
sudo apt-get install monodevelop

ติดตั้ง xsp4  โดยเข้าไปดูวิธีติดตั้งได้ที่

https://zxtech.wordpress.com/2015/01/04/how-to-install-xsp4-onto-ubuntu/

จากนั้นเปิดโปรแกรม mono สร้าง project asp.net web form แล้วเขียนโปรแกรมตามต้องการ แล้ว run














หากต้องการใช้งาน vb.net ก็ติดตั้งโดยพิมพ์คำสั่ง

sudo apt-get install monodevelop mono-vbnc

การติดตั้ง SSH

sudo apt-get install openssh-server
.ให้ทำการตรวจสอบสถานะ ssh
sudo service ssh status

คำสั่งในการเปิดใช้งาน
sudo service ssh start
จากนั้นก็ติดต่อโดยใช้ putty จากเครื่องใดๆ ในเน็ทเวิร์ค

การติดตั่้ง OwnCloud
ให้เลือกติดตั้งตามรุ่นของ OS ที่ใช้ ตามลิงค์ด้านล่าง
https://download.owncloud.org/download/repositories/stable/owncloud/


ปัญหาเมื่อเปิดเครื่องแล้ว จอไม่ขึ้นอะไรเลย มีแต่ภาพพื้นหลัง
ให้เข้าโหมด เท็กซ์ โดยกดปุ่ม Ctrl + Alt + F1 จากนั้นก็ล็อกอิน เมื่อเข้าไปแล้ว มีวิแก้ 2 วิธี ลองดูถ้าวิธีแรกได้ก็ไม่ต้องทำวิธีที 2
วิธีแก้แบบที่ 1  (ลองแล้วไม่ได้ผล แต่เครื่องอื่นไม่รู้)
     sudo apt-get update
     sudo apt-get install --reinstall ubuntu-destop
     sudo apt-get install install unity
     sudo shutdown -r now

วิธีแก้แบบที่ 2 (ล้างค่าคอนฟิกของระบบ ซึ่งไม่มีอะไรก็แค่ไปกำหนดใหม่นิดหน่อย)
     sudo rm -rf ~/.config
     sudo reboot

** อ้างอิงจาก : https://itsfoss.com/how-to-fix-no-unity-no-launcher-no-dash-in-ubuntu-12-10-quick-tip/


... ไว้มาต่อ ... 
 
"I Believe in You"

Copyright(c) 2007 - 2022 by Kasem Kamolchaipisit.