C# Addendum

The code in this chapter represents another straightforward C# port. Here it is:

HeroShipCSharp.cs

using UnityEngine;
using System.Collections;

public class HeroShipCSharp : MonoBehaviour {

    public GameObject bullet;
    public AudioClip pew;	

    private void Update()
    {
        transform.position = new Vector3(Input.mousePosition.x/20, transform.position.y, transform.position.z);
        if(Input.GetMouseButtonDown(0))
        {
            audio.PlayOneShot(pew);
            Instantiate(bullet, transform.position + new Vector3(-3,2,0), Quaternion.identity);
            Instantiate(bullet, transform.position + new Vector3(3,2,0), Quaternion.identity);
        }
    }
}

EnemyShipCSharp.cs

using UnityEngine; using System.Collections; public class EnemyShipCSharp : MonoBehaviour { public GameObject explosion; public ...

Get Unity 4.x Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.