• Home
  • About
    • Hanna's Blog photo

      Hanna's Blog

      I wanna be a global developer.

    • Learn More
    • Email
    • LinkedIn
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

[Unity 2017] Basket Ball AR

24 Nov 2018

Reading time ~2 minutes

See this unity games in github.

Game Design

  • Light
  • Event System
  • Game UI
  • Logic
  • AR Camera
  • ImageTarget
  • Basket Game

Lgith

  • Directional Light
  • Position: (0, 3, 0)
  • Rotation: (50, -30, 0)

Event System

  • EventSystem
    • To detect input

Game UI(Canvas)

  • Image
  • Button
    • Event Trigger
    • Add Logic in Event Trigger
    • Text
      • Put under Button
      • Text: “Button”
  • Score(Text)
    • Text: 0
  • Text
    • Text: “Score : “

Logic

  • Basket Control.cs
  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using UnityEngine.UI;
  using UnityEngine.SceneManagement;

  public class BasketControl : MonoBehaviour {
    public Text my_score;
    GameObject A;
    Transform B;

    static public int gamescore = 0;
    
    public GameObject basketBall;
    public Transform firepoint;
    Rigidbody ballrigid;

    public void ShootBall(){
        ballrigid.useGravity = true;
        ballrigid.AddForce(Vector3.up * 600f);
        ballrigid.AddForce(Vector3.forward *500f);
    }

  	void Start () {
      ballrigid = basketBall.GetComponent<Rigidbody>();
    }
	
  	void Update () {
      my_score.text = gamescore.ToString();
      if (basketBall.transform.position.y <= -15f){
        initball();
      }
    }

    void initball(){
      basketBall.transform.position = firepoint.transform.position;
      basketBall.transform.eulerAngles = Vector3.zero;
      ballrigid.velocity = Vector3.zero;
      ballrigid.angularVelocity = Vector3.zero;
      ballrigid.useGravity = false;
    }
  }
  • My_score: score
  • Basket Ball: BasketBall
  • Firepoint: FirePoint

AR Camera

  • Vuforia
    • Download vuforia and import
    • Open Vuforia
    • Register or Login
    • Click Develop Menu
    • Create Development Key
    • Vuforia Behavior>Open Vuforia configutration
    • Copy and Paste License Key of Vuforia
    Basket Ball AR Vuforia

Image Target

  • ImageTarget
    • Asset>Vuforia>Prefabs>ImageTarget
    • Drag and drop to Hierarchy
    • In Vuforia, Develop>Target Manager>Add Database
    • Create Database
    • Develop>Target Manager>Databse Name>Add Target
    • Create target
    • Develop>Target Manager>Database Name>Download Database
    Basket Ball AR Image Target
    • Import Target and drag and drop to Image Target
  • Set Target Behaviour
    • Image Target>Inspector>Image Target Behaviour
    • Change Database and Image Target
    Basket Ball AR Image Target

Basket Game

  • Stand
    • Cube
  • BasketBall
    • Sphere
    • Physic Material
      Dynamic Friction: 0.6
      Static Friction: 0.6
      Bounciness: 0.6
      Friction Combine: Maximum
    • Rigidbody
      Use Gravity: Check
    • Ball Control.cs
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;

      public class BallControl : MonoBehaviour {

	      void Start () {
          this.gameObject.GetComponent<Rigidbody>().useGravity = false;
	      }

        void OnTriggerEnter(Collider other){
          if (other.gameObject.name == "score_box"){
            BasketControl.gamescore += 1;
            print(BasketControl.gamescore);
          }
        }

          void Update () { }
      }
    
  • FirePoint
    • Empty Object
  • basket
    • Import Asset
  • score_box
    • Cube
    • Is Trigger: Check
    • Mesh Renderer: Uncheck

UI

Basket Ball AR

Demo Video

Download



UnityC#ARVRGame Share Tweet +1