Search Unity

Will Goldstone's Unity 3.x Game Development Essentials

Discussion in 'Community Learning & Teaching' started by HPMPRacer, Jul 20, 2014.

  1. HPMPRacer

    HPMPRacer

    Joined:
    Feb 16, 2014
    Posts:
    28
    All,

    I have run into an roadblock while trying to complete Will Goldstone's Unity 3.x Game Development Essentials. I am running Unity 4.5.2 and I know the book is based on versions 3.x, however, I was able to complete the first prototype but have run into a snag beginning with the Terrain editor.

    In the section titled "Creating the Island - sun, sea and sand." It says to set the Terrain Height to 30 and then use the reverse of Terrain Raise to minimize the outsides, which creates the effect of a coast line.

    I have set my Height to 30 and I am trying to minimize the height to create a coast line but nothing is working.
     
  2. christinanorwood

    christinanorwood

    Joined:
    Aug 9, 2013
    Posts:
    402
    When you set the height to 30 (in the terrain script, second button in the editor, not in the Terrain settings, where height means maximum height), click on Flatten and it will set your entire terrain at a height of 30.
     
    HPMPRacer likes this.
  3. HPMPRacer

    HPMPRacer

    Joined:
    Feb 16, 2014
    Posts:
    28
    Thank you! This solved my issue! Very appreciative for your help. Have you completed the entire demo game in this book?
     
  4. christinanorwood

    christinanorwood

    Joined:
    Aug 9, 2013
    Posts:
    402
    Not yet. I've got a few different resources. I'll work through them all eventually.
     
  5. HPMPRacer

    HPMPRacer

    Joined:
    Feb 16, 2014
    Posts:
    28
    Between the two scripting languages, C# and Javascript, are there scenario's where one language is more appropriate to use than the other?
     
  6. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    I've found that writing scripts that can be accessed by other scripts is easier with C#, this is usually the case with multiplayer games, or networked games. I've built a couple multiplayer prototypes and was only able to achieve functionality with C#. I think it can be done with Javascript, but C# is just better in my opinion.

    For my single player games I use Javascript because it's just easy for me to write basic code in. Eventually I'll fully convert to C#, so it would be easier for me to turn a single player game into a multiplayer game.
     
  7. HPMPRacer

    HPMPRacer

    Joined:
    Feb 16, 2014
    Posts:
    28
    @TurnTheGameOn - I am relieved to hear that C# is the better option as it is the language I have been performing the tutorials in.
     
  8. HPMPRacer

    HPMPRacer

    Joined:
    Feb 16, 2014
    Posts:
    28
    So I have run into another problem.

    In the section of the booked called "Scripting for Trigger Conditions" I have written the example code line for line but I cannot get the Trigger Collision Detection example to work. I manually made the FPS object's tag as "Player" but still not luck.

    Has anyone else run into this issue?
     
  9. HPMPRacer

    HPMPRacer

    Joined:
    Feb 16, 2014
    Posts:
    28
    Some additional context.

    the outPost object has the Triggerzone C# script attached to it.
    the outPost object has a Box Collider, with Is Trigger checked.
    The first person object has been tagged as "Player".
    PlayerCollions has been removed.

    My character is well within the Box Collider but for some reason the collider isnt detecting my character.
     
    Last edited: Aug 4, 2014
  10. HPMPRacer

    HPMPRacer

    Joined:
    Feb 16, 2014
    Posts:
    28
    Anyone kind enough to post their TriggerZone C# code?

    I'm perplexed as to why this isn't working.
     
  11. HPMPRacer

    HPMPRacer

    Joined:
    Feb 16, 2014
    Posts:
    28
    All,

    I am completely dumbfounded over my Character not being detected within the Trigger Box Collider. Maybe some can do a quick check of the book's code and see if I have made and error?

    There are three scripts; DoorManager, PlayerCollisions and TriggerZone. The first two work fine for door opening with RayCasting. The TriggerZone script is almost identical to PlayerCollisions but for some reason I've got no dice.

    Note - the First Person Controller is tagged as "Player" and the Box Collider on my outPost is set to Is Trigger. Conceptually it seems so easy but no luck so far.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class DoorManager : MonoBehaviour {
    5.  
    6.     bool doorIsOpen = false;
    7.     float doorTimer = 0.0f;
    8.     public float doorOpenTime = 3.0f;
    9.     public AudioClip doorOpenSound;
    10.     public AudioClip doorShutSound;
    11.  
    12.  
    13.     // Use this for initialization
    14.     void Start () {
    15.         doorTimer = 0.0f;
    16.     }
    17.  
    18.     // Update is called once per frame
    19.     void Update () {
    20.      
    21.         //page 467 Reversing the procedure (close the door)
    22.         if (doorIsOpen) {
    23.          
    24.             //Time.deltaTime adds one increment to the doorTimer variable each frame, 3 increments = 3 seconds
    25.             doorTimer += Time.deltaTime;
    26.          
    27.             //on the fourth second the Timer exceeds the doorOpenTime and the door is closed.  Reset the doorTimer
    28.             if(doorTimer > doorOpenTime) {
    29.                 Door(doorShutSound, false, "doorshut");
    30.                 doorTimer = 0.0f;  
    31.             }
    32.          
    33.         }
    34.      
    35.     }
    36.  
    37.     void DoorCheck(){
    38.                 if(!doorIsOpen){
    39.                         Door(doorOpenSound, true, "dooropen");
    40.                 }
    41.         }
    42.  
    43.     void Door(AudioClip aClip, bool openCheck, string animName){
    44.         audio.PlayOneShot(aClip);
    45.         doorIsOpen = openCheck;
    46.         transform.parent.animation.Play(animName);
    47.     }
    48. }
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class playerCollisions : MonoBehaviour {
    5.  
    6.     public GameObject currentDoor;
    7.  
    8.     // Update is called once per frame
    9.     void Update () {
    10.  
    11.         RaycastHit hit;
    12.  
    13.         //Physics.Raycast casts the ray
    14.         if(Physics.Raycast (transform.position, transform.forward, out hit, 3)) {
    15.             if(hit.collider.gameObject.tag=="playerDoor"){
    16.                 currentDoor = hit.collider.gameObject;
    17.                 currentDoor.SendMessage("DoorCheck");
    18.             }
    19.         }
    20.     }
    21. }
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TriggerZone : MonoBehaviour {
    5.  
    6.     void Start (){
    7.         }
    8.  
    9.     void Update(){
    10.         }
    11.  
    12.     void onTriggerEnter(Collider col){
    13.  
    14.         if(col.gameObject.tag == "Player"){
    15.             transform.FindChild("door").SendMessage("DoorCheck");
    16.         }
    17.  
    18.     }
    19.    
    20. }