Skip to content
Snippets Groups Projects
Commit fb58d47b authored by yusufrahmatp's avatar yusufrahmatp
Browse files

Add score and score addition if goal

parent 081521db
No related merge requests found
......@@ -13,7 +13,7 @@ GameObject:
- component: {fileID: 1080256283480926431}
- component: {fileID: 1080256283487850207}
- component: {fileID: 1080256283479823743}
- component: {fileID: 1080256283489944575}
- component: {fileID: 9063117224117505378}
- component: {fileID: 1080256283489944573}
- component: {fileID: 6502165512040825303}
m_Layer: 9
......@@ -111,7 +111,7 @@ Rigidbody:
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!114 &1080256283489944575
--- !u!114 &9063117224117505378
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
......
using System;
using UnityEngine;
using UnityGame;
namespace UnityStandardAssets.Vehicles.Ball
{
public class Ball : MonoBehaviour
{
[SerializeField] private float m_MovePower = 5; // The force added to the ball to move it.
[SerializeField] private bool m_UseTorque = true; // Whether or not to use torque to move the ball.
[SerializeField] private float m_MaxAngularVelocity = 25; // The maximum velocity the ball can rotate at.
[SerializeField] private float m_JumpPower = 2; // The force added to the ball when it jumps.
private const float k_GroundRayLength = 1f; // The length of the ray to check if the ball is grounded.
private Rigidbody m_Rigidbody;
private Transform target;
public AudioSource audio;
private GameController gameController;
private void Start()
{
m_Rigidbody = GetComponent<Rigidbody>();
// Set the maximum angular velocity.
GetComponent<Rigidbody>().maxAngularVelocity = m_MaxAngularVelocity;
target = GameObject.FindWithTag("MainCamera").transform;
Move(target.forward, false);
audio = GetComponent<AudioSource>();
GameObject gameControllerObject = GameObject.FindWithTag("GameController");
if (gameControllerObject != null)
{
gameController = gameControllerObject.GetComponent<GameController>();
}
if (gameController == null)
{
Debug.Log("Cannot find 'GameController' script!");
}
}
public void Move(Vector3 moveDirection, bool jump)
{
// If using torque to rotate the ball...
if (m_UseTorque)
{
// ... add torque around the axis defined by the move direction.
m_Rigidbody.AddTorque(new Vector3(moveDirection.z, 0, -moveDirection.x)*m_MovePower);
}
else
{
// Otherwise add force in the move direction.
m_Rigidbody.AddForce(moveDirection*m_MovePower);
}
// If on the ground and jump is pressed...
if (Physics.Raycast(transform.position, -Vector3.up, k_GroundRayLength) && jump)
{
// ... add force in upwards.
m_Rigidbody.AddForce(Vector3.up*m_JumpPower, ForceMode.Impulse);
}
}
void OnTriggerEnter (Collider collider)
{
audio.Play(0);
gameController.AddScore(1);
}
}
}
fileFormatVersion: 2
guid: 388f256e5595a6745959f3d27f392d2f
guid: e004fefca5c7ba44d9c5ffd46fdee2ed
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -47,8 +47,6 @@ namespace UnityStandardAssets.Characters.FirstPerson
public Transform shotSpawn;
public float fireRate;
private GameController gameController;
// Use this for initialization
private void Start()
{
......@@ -62,16 +60,6 @@ namespace UnityStandardAssets.Characters.FirstPerson
m_Jumping = false;
m_AudioSource = GetComponent<AudioSource>();
m_MouseLook.Init(transform , m_Camera.transform);
GameObject gameControllerObject = GameObject.FindWithTag("GameController");
if (gameControllerObject != null)
{
gameController = gameControllerObject.GetComponent<GameController>();
}
if (gameController == null)
{
Debug.Log("Cannot find 'GameController' script!");
}
}
......@@ -103,7 +91,6 @@ namespace UnityStandardAssets.Characters.FirstPerson
{
nextShot = Time.time + fireRate;
Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
gameController.AddScore(1);
}
}
......
......@@ -4,7 +4,7 @@ using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityEngine;
namespace UnityStandardAssets.Characters.FirstPerson
namespace UnityGame
{
public class GameController : MonoBehaviour
{
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScoringSoundEffect : MonoBehaviour
{
public AudioSource audio;
// Start is called before the first frame update
void Start()
{
audio = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter (Collider other)
{
audio.Play(0);
}
}
......@@ -15,7 +15,6 @@ namespace UnityStandardAssets.Vehicles.Ball
private Transform target;
public AudioSource audio;
private void Start()
{
m_Rigidbody = GetComponent<Rigidbody>();
......
fileFormatVersion: 2
guid: e004fefca5c7ba44d9c5ffd46fdee2ed
guid: 9c83c503dc089f2428afb6f06d8391a2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
No preview for this file type
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment