Skip to content

Instantly share code, notes, and snippets.

@ApprenticeGC
Last active June 24, 2017 21:30
Show Gist options
  • Select an option

  • Save ApprenticeGC/49103d8d8e5b25c152e5dc222df047b8 to your computer and use it in GitHub Desktop.

Select an option

Save ApprenticeGC/49103d8d8e5b25c152e5dc222df047b8 to your computer and use it in GitHub Desktop.
Unity sample project, roll-a-ball F# version
namespace RollABall
open UnityEngine
type CameraController() =
inherit UnityEngine.MonoBehaviour()
[<DefaultValue>] val mutable player : GameObject
let mutable offset : Vector3 = Unchecked.defaultof<Vector3>
member this.Start() =
offset <- this.transform.position - this.player.transform.position
member this.LateUpdate() =
this.transform.position <- this.player.transform.position + offset
namespace RollABall
open UnityEngine
open UnityEngine.UI
type PlayerController() =
inherit UnityEngine.MonoBehaviour()
[<DefaultValue>] val mutable speed : float32
[<DefaultValue>] val mutable conutText : Text
[<DefaultValue>] val mutable winText : Text
let mutable rb : Rigidbody = Unchecked.defaultof<Rigidbody>
let mutable count : int = 0
member this.Start() =
rb <- this.GetComponent<Rigidbody>()
count <- 0
this.SetCountText()
this.winText.text <- ""
member this.FixedUpdate() =
let moveHorizontal = Input.GetAxis ("Horizontal")
let moveVertical = Input.GetAxis ("Vertical")
let movement = new Vector3 (moveHorizontal, 0.0f, moveVertical)
(movement * this.speed) |> rb.AddForce
member this.OnTriggerEnter(other : Collider) =
if other.gameObject.CompareTag("Pick Up") then
false |> other.gameObject.SetActive
count <- count + 1
this.SetCountText()
member this.SetCountText() =
let countDesc = sprintf "Count: %i" count
this.conutText.text <- countDesc
if count >= 12 then
this.winText.text <- "You win"
namespace RollABall
open UnityEngine
type Rotator() =
inherit UnityEngine.MonoBehaviour()
member this.Update() =
(new Vector3(15.0f, 30.0f, 45.0f) * Time.deltaTime) |> this.transform.Rotate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment