This was a team project where we designed and demoed a sequel to 'StoryToys' kids game 'Animal Band'. On this Project I handled the coding and actually built the level in Unity.
The code
Character Movement
​
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
​
public class CharacterMovement : MonoBehaviour {
public float maxSpeed = 10f;
float move;
float move2;
Rigidbody2D rb;
bool Duck;
GameObject player;
bool facingRight = true;
void Awake () {
rb = GetComponent<Rigidbody2D> ();
}
void FixedUpdate () {
move = Input.GetAxis ("Horizontal");
rb.velocity = new Vector2 (move * maxSpeed, rb.velocity.y);
}
}
Passenger Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PassengerScript : MonoBehaviour {
Rigidbody2D colRB;
Rigidbody2D busRB;
public GameObject seat;
public GameObject bus;
public LevelManager theLM;
bool range = false;
public Animator scoreAnim;
void Start ()
{
theLM = GameObject.FindGameObjectWithTag("LM").GetComponent<LevelManager>();
busRB = GameObject.FindGameObjectWithTag("bus").GetComponent<Rigidbody2D>();
scoreAnim = GameObject.FindGameObjectWithTag("Score").GetComponent<Animator>();
}
void Update ()
{
if (range == true && busRB.velocity == new Vector2(0, 0))
{
Debug.Log("Success");
gameObject.transform.position = seat.transform.position;
gameObject.transform.parent = bus.transform;
if (gameObject.tag.Equals("PS1"))
{
scoreAnim.SetBool("Elephant", true);
Debug.Log("e");
}
if (gameObject.tag.Equals("PS2"))
{
scoreAnim.SetBool("Hippo", true);
Debug.Log("e");
}
if (gameObject.tag.Equals("PS3"))
{
scoreAnim.SetBool("Sheep", true);
Debug.Log("e");
}
if (gameObject.tag.Equals("PS4"))
{
scoreAnim.SetBool("Mouse", true);
Debug.Log("e");
}
}
}
public void OnTriggerEnter2D(Collider2D collision)
{
Debug.Log("collision");
range = true;
}
public void OnTriggerExit2D(Collider2D collision)
{
range = false;
}
}