Search Unity

Beginning 3D Game Development with Unity 4

Discussion in 'Community Learning & Teaching' started by k3D-Junkie, Sep 10, 2013.

  1. GameTech

    GameTech

    Joined:
    Dec 26, 2012
    Posts:
    53
    hi Sue, no the look-at target object has no parent. Basically what appears to be happening is it reverts back to the original rotation right before the match starts. So it starts at a certain rotation then goes back to it. I want it to just stay at its ending rotation. I can't tell why it does that though.
     
  2. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    right- that's the whole point- it should finish and remain that way :)

    I'll have a look at it and see if I can spot the problem
     
  3. tholland

    tholland

    Joined:
    May 28, 2009
    Posts:
    129
    @Tony, I looked at my chapter 16 project and the prefab's name is Kahmi, (as is the child root motion object, unfortunately), so it should always read 'the Kahmi prefab'. I think at one time I had the prefab named Kahmi Prefab because of the ambiguity, but changed it
    No idea about the "newer objects"- what chapter and how many pages in? (my version only has per chapter pages)

    Thanks Sue. It's chapter 16 and 55 pages in "9. Update the Kahmi and Gimbok prefabs by dragging the newer objects onto them or by clicking Apply at5 the top of the Inspector"

    Sorry Sue but I still don't understand the naming of Kahmi. In the text there are references to "Kahmi prefab" and also to "Kahmi Prefab". There is an object called "Kahmi Prefab" which contains a prefab "Kahmi" and it is not clear which of these prefabs is to receive the Interactor and ObjectLookup scripts. I am obviously doing something wrong because Npc 2 (Kahmi) cannot access the Interactor script attached to it. I have also tried swapping Interactor around between the two prefabs, but again Kahmi cannot access the Interactor script. As a result I am getting a null reference exception error. The error is generated by this line in the Update function of the DialogueManager:
    character [currentNpc].GetComponent (Interactor).processing = false;
    Any help would be appreciated.
     
    Last edited: May 3, 2014
  4. GameTech

    GameTech

    Joined:
    Dec 26, 2012
    Posts:
    53
    Hi Sue,

    I have another problem. I know you probably can't give details, but what might possibly be causing a screen flash, anything that might cause it? Here is a testing video of my survival horror adventure game, after I click the turkey on the zombie dog, the screen flashes and I have no idea why. It is not the screen inventory white screen, it is a bluish tint.
     
  5. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    @GameTech-
    It looks like the inventory screen to me- try making the inventory background fully transparent see if you still see the flash
    re camera match- haven't had time to set up a test scene for that yet

    @Tony-
    You are so right, I opened a later chapter and the Kahmi character has been turned into Kahmi Prefab- my apologies.
    I show the Interactor on the parent-most gameObject. Also, make sure the ID for Kahmi is 2.
    Better idea- zip upload the whole project to my Dropbox folder so I can see where it goes wrong. My chapter 16 didn't work like I remember it working, so I may as well dig through yours.

    Sue
     
  6. GameTech

    GameTech

    Joined:
    Dec 26, 2012
    Posts:
    53
    Hi Sue,

    I changed it to transparent and the screen flashes are still there. If there was heavy processing going on would that cause a screen flash or is it more likely to be some kind of gui texture or something?
     
  7. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    it's probably an object, 2D or 3D, I'd start looking at the 2D stuff first- maybe some of the screen effects? light flares?
     
    Last edited: May 6, 2014
  8. WhispersInTheRain

    WhispersInTheRain

    Joined:
    May 14, 2014
    Posts:
    4
    So I just picked up your book, absolutely loving it so far except I just hit a section where it tells me to access some assets specifically for the book project. I tried to download them off the Apress website and it either won't start or just keeps starting and then resetting back to 0% and starting again. Is there any other way for me to download the necessary assets?
     
  9. tholland

    tholland

    Joined:
    May 28, 2009
    Posts:
    129
    Hi Sue

    I loaded the project (Book Project2) into your dropbox about ten days ago, but don't know if you have picked it up - email contact doesn't seem to be working.

    Best wishes

    Tony
     
  10. Kashrlyyk

    Kashrlyyk

    Joined:
    Aug 16, 2011
    Posts:
    17
    Code (csharp):
    1. public int[] uiReply = new int[6];
    Found the problem. The definition creates uiReply with a length of zero. Why?

    FOUND THE SOLUTION: Remove "public". Somehow "public" overwrote the "6" in "int[6]".
     
    Last edited: May 24, 2014
  11. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    hi Kashrlyyk,

    Yeah, when you make a var public so it shows in the Inspector, the value in the Inspector always overrides whatever you have set it to in the script. If you re-assign the value in the Start menu, then that will override the value in the Inspector.

    I won't tell you how many times I've been caught out by public variables :) (and I know better!)

    Sue
     
  12. difficultnerd

    difficultnerd

    Joined:
    May 3, 2014
    Posts:
    52
    Hey Everyone,
    I've been reading Ms Blackman's book and absolutely love it - her style is brilliant, accessible and informative. I find the examples are really exactly what I need to learn this SDK.

    The only issue that I've run into an issue which I can't find a solution to -

    I've gone through Chapter 6 several times and keep getting the following error:


    NullReferenceException: Object reference not set to an instance of an object
    UnityEngine.GUI.DrawTexture (Rect position, UnityEngine.Texture image, ScaleMode scaleMode, Boolean alphaBlend, Single imageAspect)
    UnityEngine.GUI.DrawTexture (Rect position, UnityEngine.Texture image)
    GameManager.Update () (at Assets/Adventure Scripts/GameManager.js:45)
    So I load up GameManager.js and go to line 45 -

    Code (JavaScript):
    1.   GUI.DrawTexture (Rect(pos.x,Screen.height - pos.y,64,64),currentCursor); // draw the cursor
    which implies that currentCursor is the issue, so I went and checked the declaration -

    Code (JavaScript):
    1. internal var currentCursor:Texture; // the current cursor texture
    To my eyes this looks fine (I've tried with different whitespacing, no change). So the issue must be in how the "current cursor" gets defined, which is in the start function -

    Code (JavaScript):
    1. function Start () {
    2.  
    3.         Screen.showCursor = false; //hide the operating system cursor
    4.         currentCursorColor = Color.white;  // start colour to white
    5.         currentCursor = defaultCursor; // assign the default cursor to the current cursor
    6.  
    7. }
    Usually at this point I want to throw something in frustration. My Mac perhaps?

    So I check that I "linked" the texture correctly -
    1. I've imported GamePointerOffset from the zip file
    2. It's in the 'Adventure Texture' folder we created
    3. I've dragged it from there, onto the "default cursor" spot on the inspector, as you can see in the following screen cap:
    Screen Shot 2014-06-09 at 10.44.39 pm.png

    Here is the complete Update function in case anyone can see something I keep missing -

    Code (JavaScript):
    1. function Update () {
    2.  
    3.     if (Input.GetAxis("Horizontal") || Input.GetAxis ("Vertical") ||
    4.          Input.GetAxis ("Turn") || Input.GetButton("ML Enable") ) {
    5.         //a navigation key is being pressed
    6.         navigating = true ; // player is moving
    7.         }
    8.        
    9.        
    10.         else {
    11.         // no navigation keys are being pressed
    12.         navigating = false; // player is stationary
    13.        
    14.         }
    15.  
    16.        
    17.     if (!navigating) { // if not navigating
    18.              var pos : Vector2 = Input.mousePosition; //get the location of the cursor
    19.              GUI.DrawTexture (Rect(pos.x,Screen.height - pos.y,64,64),currentCursor); // draw the cursor
    20.              }
    21.        
    22. }
    23.  
    Any ideas what I'm missing?
     
  13. difficultnerd

    difficultnerd

    Joined:
    May 3, 2014
    Posts:
    52
    Isn't it amazing how after you lay it all out you happen across the issue -

    I misread the text - the code snippet:

    Code (JavaScript):
    1.     if (!navigating) { // if not navigating
    2.           var pos : Vector2 = Input.mousePosition; //get the location of the cursor
    3.              GUI.DrawTexture (Rect(pos.x,Screen.height - pos.y,64,64),currentCursor); // draw the cursor
    4.              }
    shouldn't be in "update" - this was a 'duplicate' of the if (navigating == false) statement in OnGUI.

    I found a forum posting that made it clear to me that these GUI functions can only occur in 'onGUI'.

    My excuse for this rookie mistake is that Ms Blackman's book is such a page turner that I'm not sleeping properly, and at 11pm here in Melbourne, well I'm sure you all get it :)

    Congrats on an excellent book, Ms Blackman.
     
  14. difficultnerd

    difficultnerd

    Joined:
    May 3, 2014
    Posts:
    52
  15. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    can't get to thread again, and it would help me to match the photos to the book {my pages don't match}
     
  16. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    ok guys, give this a try & let me know if I've missed something. It doesn't really tell you anything about Mecanim, but should get the key fading out.

    Animating the Key At Rock with Mecanim

    The animated color/opacity only works with Mecanim's Animator component, but we now have a way to call the clip directly without having to deal with blending. You will need to change the key's shader to Transparent/Bumped Specular for it to show the results of the opacity animation.

    1. Deactivate the Rock (so you can see the Key At Rock)
    2. Duplicate Key At Rock in the Animation Objects group
    3. Drag the duplicate out of the group & disable the original (this keeps the prefab from breaking)
    4. Open the Animation view- you should see Add Curve (the other animation was on the group, so you won't see all of the read-only tracks this time, it also defaults to Dope Sheet rather than Curves view)
    5. Click Add Curve (this puts you into a dialog to name the new clip)
    6. Create a new curve in the Animation Clips folder- this adds an Animator component to the object (the "record" button has also been turned on)
    7. Don't bother selecting a track- move the time indicator to 1:00 (once you have figured this out, use the times/keyframes in the book)
    8. Lift the key up in the viewport (this creates the keys & tracks for the transform)
    9. Set the key's Main Color opacity value to 0 in the Inspector. (the color.a track and Mesh Renderer tracks are added)
    10. Move the time indicator back to frame 0 & set the opacity to 1(100%) in the Animation editor or the Inspector 255(100%)
    11. Switch to the Curves view (bottom of Animation editor) and adjust curves as per book
    Tip: setting the keys to "Flat" will give you a classic ease-in/ease-out curve
    -------------------
    1. Select the new animation clip in the Project view
    2. Uncheck Loop Time in the Inspector
    3. Click Play- the animation plays immediately
    4. Double click on the Animator component's Controller (it is assigned the same name as the rock, or incremented if there is already one of that name) to open the Animator View (you will see the state with the animation clip's name)
    5. Right click in the animator window and Create State - Empty
    6. Click on it, right click and Set as Default (this will prevent the clip's state from playing immediately)
    7. Click Play, it no longer animates right away (now you need to trigger it from code)

    -------------------
    1. Open the AniTest script
    2. Add: var animator : Animator; // the animator component
    3. Add if(aniParent) to aniParent. animation.Play(aniClip.name); // check for parent first
    4. Below that line, add: if(animator) animator.Play(aniClip.name,0,0.0); //check for an animator component first
    (the first argument is the state name which is the clip name, a String, unless you've changed it, the second argument is the layer, 0, and the third argument is where you want it to play from, in this case 0, the start)
    5. Add the AniTest script to the key
    6. Fill in the parameters in the Inspector (drag the key itself onto its Ani Test's Animator parameter)
    7. Duplicate the Animation Objects group and remove all but the rock, name the new group Rock Group
    8. Deactivate the rock in the original group & activate the duplicate.
    9. Click Play and make sure that it still works.
    10. Create a new parent group for the rock and key (the Mecanim animation doesn't play correctly if there is already an Animation component on the parent group)
    11. Drag the key and Rock Group into the new parent group (because you will want to move the rock & key together around the scene at some point)
    12. Click Play and test.

    Note: I haven’t tested the key At Lock yet, but suspect it may have to have its imported animation switched over to Mecanim in the import settings in order to add a well behaved fade out to it. That would require everything to be switched over, so probably won't happen until the next edition of the book.

    Hope this helps,
    Sue
     
    koutchieman likes this.
  17. WhispersInTheRain

    WhispersInTheRain

    Joined:
    May 14, 2014
    Posts:
    4
    I might have modified the script wrong but I kept getting an error saying that it could not find a animation clip attached to the KeyAtRock object even though it was in the scripts components. Could you perhaps post a copy of what the entire script looks like so I know I am adding in the new lines properly
     
  18. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    I don't have it with me right now, but...

    comment out the original animation.Play line & see if that helps

    the Mecanim version is only using the name of the clip, shouldn't care if it is attached
    or try hard-coding the name in instead of referencing the clip's name (remember " ")
     
  19. fitpixel

    fitpixel

    Joined:
    Apr 3, 2014
    Posts:
    2
    Dear Sue:

    So I've done something crazy. I'm converting JS to C# on the fly while going through your book.

    I'm also using your book as a reference to make my own adventure game instead of using your assets, and thus far it has gone swimmingly. Seriously, your explanations are spot on and I've had very little trouble working my way through your book.

    But I have this error and it's been driving me bonkers.

    In my inventory (which uses basically the same code) I have two objects that when combined are consumed, and then a new object SHOULD appear in the inventory.

    This is the error I'm getting:
    UnassignedReferenceException: The variable auxObject of ObjectLookup has not been assigned.

    The two objects consume properly, get into cursor properly, show up in the inventory...but dammit the auxiliary object just won't process. It says the error is on line 109, but the more I debug.log I think it's actually getting hung up in CheckForActive(). Or maybe it's just me putting things wrong in the inspector. I really have not a clue any more.

    Any insite at all would be most appreciated.

    SCREENSHOTS



    OBJECTLOOKUP.CS
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class ObjectLookup : MonoBehaviour
    6. {
    7.  
    8.     //Variables for the lookup states
    9.     public int state = 1;
    10.  
    11.     public string[] lookupState1 = new string[3];
    12.     public string[] lookupState2 = new string[3];
    13.     public string[] lookupState3 = new string[3];  
    14.  
    15.     internal string[] currentStateArray = new string[3];
    16.  
    17.     //Variables for the replies for each state
    18.     public string[] repliesState1 = new string[3];
    19.     public string[] repliesState2 = new string[3];
    20.     public string[] repliesState3 = new string[3];
    21.  
    22.     public string[] genericReplies = new string[3]; //Generic reply for each state in case something werid happens
    23.                                                    //Need one for each state
    24.     internal string[] currentReplyArray = new string[3];//Holds the current reply to process
    25.     //call the control center
    26.     public GameObject controlCenter;
    27.     public GameObject auxObject;
    28.  
    29.      
    30.     // Update is called once per frame
    31.  
    32.     void Update ()
    33.     {
    34.  
    35.     }
    36.  
    37.     void Start()
    38.     {
    39.         controlCenter = GameObject.Find("GameManager");
    40.     }
    41.  
    42.     public void LookUpState(GameObject whichObject, int currentState, string picker)
    43.     {  
    44.         state = currentState;//assign current state to the state variable
    45.         string matchCursor = picker; //temporary to hold the temp cursor texture name
    46.         Debug.Log("Are you getting to the SwitchCase?");
    47.         switch(state)
    48.         {
    49.             case 1:
    50.             currentStateArray = lookupState1;
    51.             currentReplyArray = repliesState1;
    52.             break;
    53.  
    54.             case 2:
    55.             currentStateArray = lookupState2;
    56.             currentReplyArray = repliesState2;
    57.             break;
    58.  
    59.             case 3:
    60.             currentStateArray = lookupState3;
    61.             currentReplyArray = repliesState3;
    62.             break;
    63.         }
    64.  
    65.         int element = 0;//variable to track the element number for a match
    66.         bool match = false;
    67.         Debug.Log("RESULTS FOR STATE " + state );
    68.      
    69.         foreach(string contents in currentStateArray)
    70.         {
    71.             Debug.Log("Contents of state:" + contents);
    72.          
    73.             string[] readString = contents.Split(new char[] {','});
    74.          
    75.             Debug.Log("Elements in Array for State " + state + " = " + readString.Length);
    76.             Debug.Log("Cursor = " + readString[0]);
    77.             Debug.Log("New State = " + readString[1]);
    78.  
    79.             //Check for a cursor match with element 0 of the split
    80.             if(readString[0] == matchCursor)
    81.             {
    82.                 Debug.Log("In readString.");
    83.  
    84.                 match = true;
    85.                 //print(currentReplyArray[element]); //okay so it is showing up in the console
    86.                 controlCenter.GetComponent<GameData>().actionMsg = currentReplyArray[element];
    87.                 //get the new state, element 1 of the split, then convert the string to an int
    88.                 int nextState = int.Parse(readString[1]);
    89.                 //transition the object into the new state over in the Interactor script
    90.                 SendMessage("ProcessObject", nextState);
    91.                 //now read through the remaninder in pairs
    92.                 //iterate through the array starting at element 2 and incrementing by 2
    93.                 //as long as the counting variable i is less than the length of the array
    94.                 for (int i = 2; i < readString.Length; i = i+2)
    95.                 {
    96.                     Debug.Log("Auxiliary object = " + readString[i]);
    97.                     Debug.Log(readString[i] + "'s new state = " + readString[i+1]);
    98.                     //assign the first peice of data in the pair to a temp variable for processing
    99.                     string tempS = readString[i];
    100.                     Debug.Log(tempS);
    101.                     //check for special cases here
    102.                  
    103.                     //find an activate the object using its name
    104.                     GameObject auxObject = CheckForActive(tempS);
    105.                     Debug.Log(tempS);
    106.                     //conver the new state from a string value to an integer for use
    107.                     int newState = int.Parse(readString[i+1]);
    108.                     //process the auxiliary objext into the new state
    109.                     auxObject.SendMessage("ProcessObject", newState, SendMessageOptions.DontRequireReceiver); // <----ERROR, says this line for the Unassigned Reference Exception, on Egypt Label Icon.          
    110.                  
    111.                 }
    112.             }
    113.  
    114.             element ++; //increment the counter by 1 for each
    115.         }
    116.         if(!match)      
    117.         {  
    118.             SendMessage("HandleNoMatchReplies", picker);
    119.         }
    120.     }
    121.  
    122.     public GameObject CheckForActive (string name)
    123.     {      
    124.         Debug.Log("Did you check for active objects?");
    125.         Debug.Log(name);
    126.         //check to see if the object is active before assigning it to the auxObject
    127.         if(GameObject.Find(name))
    128.         {
    129.             Debug.Log("HERE??");
    130.             auxObject = GameObject.Find(name);
    131.             Debug.Log(auxObject);
    132.             return auxObject;//return the gameObject to where the function was called
    133.         }
    134.         else
    135.         {
    136.             Debug.Log("Into the else statement?");
    137.             GameObject[] actionObjects = new GameObject[0];
    138.  
    139.             Debug.Log(actionObjects);
    140.             actionObjects = controlCenter.GetComponent<GameData>().actionObjects;
    141.             for (int x = 0; x < actionObjects.Length; x++)
    142.             {
    143.                 Debug.Log(actionObjects + "in the for loop");
    144.                 if(actionObjects[x].gameObject.name == name)//if there is a match for the name
    145.                 {
    146.                     Debug.Log("Into the if for the for loop? NAME SHOULD MATCH");
    147.                     actionObjects[x].gameObject.SetActive(true);
    148.                     auxObject = GameObject.Find(name); //assign the newly activated object
    149.                 }
    150.                 Debug.Log(auxObject);
    151.             }
    152.          
    153.             return auxObject;
    154.          
    155.         }      
    156.     }
    157.  
    158.     public IEnumerator HandleNoMatchReplies(string picker)
    159.     {
    160.      
    161.         //picker = picker.ToLower();
    162.         picker = picker.Substring(0,picker.Length - 4); //this line is to knock off the "icon" part of the name - comment out if you don't need it
    163.      
    164.         string tempObjectName = this.GetComponent<Interactor>().currentObjectName;
    165.  
    166.         string tempMsg = "The " + picker + " does not seem to effect the " + tempObjectName;
    167.      
    168.         controlCenter.GetComponent<GameData>().actionMsg = tempMsg;
    169.         controlCenter.GetComponent<GameData>().showActionMsg = true;
    170.         controlCenter.GetComponent<GameData>().NoMatchReturn();
    171.         yield return new WaitForSeconds(2.0f);
    172.         controlCenter.GetComponent<GameData>().showActionMsg = false;
    173.          
    174.     }
    175. }  
    176.  
    INTERACTOR.CS
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [RequireComponent(typeof(AudioSource))]
    5. [RequireComponent(typeof(ObjectLookup))]
    6.  
    7. public class Interactor : MonoBehaviour {
    8.     //Calling on StateManager
    9.     //private StateManager manager;
    10.     //Variables for Picks and Mouse Over
    11.     internal GameObject go;//transferring an item as a game object...
    12.     internal Transform pickable; //into a transform value to find the distance from player
    13.     internal GameObject controlCenter;
    14.     internal GameObject cam; //main camera as game object
    15.     public float triggerMoDis; //the distance the object needs to be for the playe to be able to pick it up
    16.     public float moOffset; //this is the distance to offset the mouse over - player will see that it is clickable, but will have to come closer to read the message (5,8)
    17.     internal bool picked = false; //temporarily prevent mouseover action
    18.     internal bool mousedown = false; //so I know when mousedown is true
    19.     internal bool processing = false; //so I can suspend mouseover actions or whatever actions when I need to
    20.  
    21.     //Variables for the State of each object
    22.     public int initialState = 1;
    23.     public bool objectIs3D = true;
    24.     public int[] location = new int[3];
    25.     public int[] visibility = new int[3];
    26.     public string[] objectName = new string[3];
    27.     public string[] description = new string[3];
    28.     public AnimationClip[] animationClip = new AnimationClip[3];
    29.     public float[] animationDelay = new float[3];
    30.     public AudioClip[] soundClip = new AudioClip[3];
    31.     public float[] audioDelay = new float[3];
    32.     public AnimationClip[] loopAnimation = new AnimationClip[3];
    33.     public AudioClip[] loopSoundFX = new AudioClip[3];
    34.     public bool postLoop = false;
    35.     public bool animates = false;
    36.     public GameObject aniObject;
    37.  
    38.     //State Dependant Variables
    39.     public int currentState = 1;
    40.     public int iElement = 100;
    41.     internal int currentLocation;
    42.     internal int currentVisibility;
    43.     internal string currentObjectName;
    44.     internal string currentObjectDescription;
    45.     internal AudioClip currentSound;
    46.     internal float currentAudioDelay = 0.0f;
    47.     internal AnimationClip currentAnimationClip;
    48.     internal float currentAnimationDelay = 0.0f;
    49.     //State dependant for 2D objects
    50.     internal int previousState;
    51.  
    52.  
    53.     //Variable for a temp cursor
    54.     public string cursor;
    55.     //Variables for the timer
    56.     internal bool pickTimer; //make this variable public if you want to be able to change the time on different objects
    57.     internal float pickTimerTime;
    58.     //Variables for the inventory
    59.     internal bool iMode;
    60.     internal bool oOR;
    61.     //variable for the transparency
    62.     public bool useAlpha = true; //remember each object will need to have their own material?
    63.     public Material originalMaterial;
    64.     public Color originalColor;
    65.     public Color alphaColor; //color types are vector4(RGBA)
    66.     //temp variable for shader
    67.     internal string tempShaderName;
    68.  
    69.  
    70.  
    71.  
    72.  
    73.     void Awake()
    74.     {
    75.         pickable = transform;
    76.      
    77.     }
    78.  
    79.     void Start ()
    80.     {  
    81.         cam = GameObject.FindWithTag("MainCamera");
    82.      
    83.         controlCenter = GameObject.Find("GameManager");
    84.         if(GetComponent<MeshRenderer>()) //if the object has a Meshrenderer, get its material
    85.         {
    86.             originalMaterial = GetComponent<MeshRenderer>().material;
    87.             //GO BACK TO pg 358 - I need to look into extension methods and how they work to relace substrings wit them - and the rest of the chapter just deals with visibility
    88.             //print(this + " " + "Shader: " + renderer.material.shader.name + " " + renderer.material.color.a);
    89.             //prep for auto fade by checking shader, unless specified as false
    90.             if(useAlpha) //if it isn't set to false by me
    91.             {
    92.                 useAlpha = false; // set it to false, there will be only one condition to make it true
    93.                 tempShaderName = renderer.material.shader.name; //get the shader teame, a string
    94.                 if(tempShaderName.Length > 11) //check for short names - they aren't transparent shaders
    95.                 {
    96.                     //check to see if the materials shader is a transparency shader
    97.                     if(tempShaderName.Substring(0,11) == "Transparent")
    98.                     {
    99.                         useAlpha = true;
    100.                         originalColor = renderer.material.color;
    101.                         //not sure what is going on with this line, i can't change the visibility of the renderer with this line
    102.                         //alphaColor = Color(originalColor.r, originalColor.b,originalColor.g,0);
    103.                     }
    104.                 }
    105.             }
    106.         }
    107.  
    108.  
    109.  
    110.         //load the initial values for the object
    111.         currentState = initialState;
    112.      
    113.         currentObjectName = objectName[currentState];
    114.         currentObjectDescription = description[currentState];
    115.         currentLocation = location[currentState];
    116.         currentVisibility = visibility[currentState];
    117.  
    118.         if(currentState == 1)
    119.         {  
    120.              controlCenter.GetComponent<GameData>().useText = true;
    121.         }
    122.  
    123.      
    124.     }
    125.  
    126.     void Update()
    127.     {      
    128.         if(currentState == 0)
    129.         {
    130.             if(objectIs3D && GetComponent<MeshRenderer>())
    131.             {
    132.                 transform.renderer.enabled = false;
    133.              
    134.             }
    135.         }
    136.         if(pickTimer && Time.time > pickTimerTime -1.0)//if the time is up and flag is on
    137.             {
    138.                 controlCenter.GetComponent<GameData>().suppressPointer = false;
    139.  
    140.             }
    141.         if(pickTimer && Time.time > pickTimerTime)
    142.         {
    143.             pickTimer = false;
    144.          
    145.             if(controlCenter.GetComponent<GameData>().actionObject == this.name)
    146.             {
    147.                 controlCenter.GetComponent<GameData>().showActionMsg = false;
    148.                 gameObject.SetActive(false);
    149.             }  
    150.         }  
    151.     }
    152.  
    153.     void OnMouseOver()  
    154.     {
    155.         //if any of these are true, GTFO the function
    156.         if(location[currentState] == 2)
    157.             return;  
    158.         if(objectIs3D && Vector3.Distance(cam.transform.position, transform.position) > triggerMoDis + moOffset)
    159.             return;  
    160.         if(processing)
    161.             return; //if processing something, leave the function      
    162.         iMode = controlCenter.GetComponent<GameData>().iMode;
    163.         if(iMode && gameObject.layer != 9)
    164.             return;              
    165.      
    166.         if(!objectIs3D) guiTexture.color = new Color(0.55f,0.55f,0.55f,1f);
    167.  
    168.         //activate the text vissdibility on mouseover
    169.         controlCenter.GetComponent<GameData>().showText = true;
    170.         controlCenter.GetComponent<GameData>().shortDesc = objectName[currentState];
    171.         controlCenter.GetComponent<GameData>().longDesc = description[currentState];
    172.      
    173.         if(!objectIs3D || Vector3.Distance(cam.transform.position, transform.position) <= triggerMoDis)
    174.         {
    175.             controlCenter.GetComponent<GameData>().inRange = true;
    176.         }
    177.         else
    178.         {
    179.             controlCenter.GetComponent<GameData>().inRange = false;
    180.         }
    181.      
    182.         //calculates the distance from camera and tells the cursor to  change or not  
    183.         if(objectIs3D)
    184.         {
    185.             if(Vector3.Distance(cam.transform.position, transform.position) > triggerMoDis + moOffset)
    186.             {
    187.                 controlCenter.SendMessage("CursorColorChange", false);
    188.              
    189.             }
    190.             else
    191.             {
    192.                 controlCenter.SendMessage("CursorColorChange",true);
    193.             }
    194.         }
    195.     }
    196.  
    197.     void OnMouseExit()
    198.     {
    199.         if(processing) return; //if processing something, leave the function
    200.  
    201.         if(!objectIs3D)
    202.             {
    203.                 guiTexture.color = Color.grey;
    204.             }
    205.  
    206.         //deactivate the text visibility on mouseexit
    207.         controlCenter.GetComponent<GameData>().showText = false;  
    208.         controlCenter.SendMessage("CursorColorChange", false);
    209.     }
    210.  
    211.     void OnMouseDown()
    212.     {
    213.         Debug.Log("Are you getting to Mouse Down?");
    214.         print(controlCenter.GetComponent<GameData>().currentCursor);
    215.      
    216.         if(location[currentState] == 2) //if object not pickable, get out of the function
    217.             return;
    218.  
    219.         if(objectIs3D)
    220.         {
    221.             if(Vector3.Distance(cam.transform.position, transform.position) > triggerMoDis)
    222.             {
    223.                 Debug.Log("Out of range from " + this.name);
    224.                 controlCenter.GetComponent<GameData>().showText = false;
    225.                 picked = false;
    226.             }
    227.             else
    228.             {
    229.                 Debug.Log("We have mousedown on " + this.name);
    230.             }
    231.         }
    232.      
    233.         if(processing) return; //if processing something, leave the function
    234.  
    235.         if(iMode && gameObject.layer != 9)
    236.             return;  
    237.      
    238.         controlCenter.SendMessage("CursorColorChange", false);
    239.  
    240.         //get and assign the current cursor value to current cursor
    241.         cursor = controlCenter.GetComponent<GameData>().currentCursor.name;
    242.      
    243.         if(cursor == controlCenter.GetComponent<GameData>().defaultCursor.name)
    244.         {
    245.             cursor = "default";
    246.         }
    247.      
    248.         GetComponent<ObjectLookup>().LookUpState(this.gameObject, currentState, cursor);
    249.          //check off animates in the inspector if it doesn't work
    250.      
    251.     }
    252.  
    253.     public IEnumerator ProcessObject (int newState)
    254.     {
    255.         Debug.Log("In ProcessObject");
    256.         processing = true; //if you are in this function, you are processing an object
    257.         //controlCenter.GetComponent<GameData>().suppressPointer = true;
    258.         //tell game data to show the action text (replies)
    259.  
    260.         controlCenter.GetComponent<GameData>().suppressPointer = true;
    261.                      
    262.         //deactivate the text messages
    263.         controlCenter.GetComponent<GameData>().showText = false;
    264.         controlCenter.GetComponent<GameData>().showActionMsg = true;
    265.         //Code for the timer
    266.         pickTimerTime = Time.time + 1.5f; //set the timer to go for .05 seconds
    267.         pickTimer = true;
    268.         controlCenter.GetComponent<GameData>().actionObject = this.name; //this line finds which action object started the timer first
    269.  
    270.         //HA. HAHAHAHAHHAHAHHAHAHHA
    271.         previousState = currentState;
    272.         currentState = newState; //updates the object's current state (from ObjectLookup)
    273.  
    274.      
    275.  
    276.         //update more of the data with the new state
    277.         currentObjectName = objectName[currentState];
    278.         currentObjectDescription = description[currentState];
    279.         currentLocation = location[currentState];
    280.         currentVisibility = visibility[currentState];
    281.         Debug.Log("Finished ProcessObject");
    282.  
    283.         //assign the current clip and delay and audio for the new state
    284.         if(animates)
    285.         {
    286.             currentAnimationClip = animationClip[currentState];
    287.             currentAnimationDelay = animationDelay[currentState];
    288.         }
    289.  
    290.         if(animates)
    291.         {
    292.             currentSound = soundClip[currentState];
    293.             currentAudioDelay = audioDelay[currentState];
    294.          
    295.             if(objectIs3D)
    296.             {
    297.                 HandleVisibility();
    298.             }          
    299.         }
    300.      
    301.  
    302.         if(animates && animationClip[currentState] != null)
    303.         {
    304.             if(aniObject == null)
    305.             {
    306.                 aniObject = gameObject;
    307.             }
    308.  
    309.             //pause before playing the animation
    310.             yield return new WaitForSeconds(currentAnimationDelay);
    311.             //play the animation
    312.             aniObject.animation.Play(currentAnimationClip.name);
    313.             //process audio
    314.             ProcessAudio(currentSound);
    315.             //wait some more
    316.             yield return new WaitForSeconds(currentAnimationClip.length);
    317.             //check for a looping animation to follow the primary animation
    318.             if(postLoop) //if postLoop is checked/true, there is a looping animation to trigger
    319.             {
    320.                 aniObject.animation.Play(loopAnimation[currentState].name);
    321.                 ProcessAudio(loopSoundFX[currentState]);
    322.             }
    323.  
    324.             processing = false;
    325.         }
    326.         else
    327.         {
    328.             if(!objectIs3D)
    329.             {
    330.                 Debug.Log("Print if you send to Handle2D.");
    331.                 StartCoroutine(Handle2D());
    332.              
    333.                 yield return new WaitForSeconds(.1f);
    334.             }
    335.  
    336.             ProcessAudio(currentSound);
    337.             yield return new WaitForSeconds(1.0f);
    338.             processing = false;
    339.         }
    340.     }
    341.  
    342.     public void ProcessAudio(AudioClip theClip)
    343.     {
    344.         if(theClip) //if there is a sound clip
    345.         {
    346.             if(GetComponent<AudioSource>()) //check to make sure an audio source ocmponent exists before playing
    347.             {
    348.                 audio.clip = theClip; //change the audio components assigned sound file
    349.                 audio.PlayDelayed(currentAudioDelay); //delay before playing it
    350.             }
    351.         }
    352.     }
    353.  
    354.     public IEnumerator HandleVisibility()
    355.     {
    356.         switch(currentVisibility)
    357.         {
    358.             case 0: //deactive immediately, no fades as per GameNotes
    359.             Debug.Log("Get past the case?");
    360.             if(currentLocation == 0)
    361.             {
    362.                 controlCenter.GetComponent<GameData>().EmergencyTimer(this.name);
    363.                 yield return new WaitForSeconds(2.0f);
    364.                 gameObject.SetActive(false);              
    365.             }
    366.          
    367.             break;
    368.  
    369.             case 1: //active at start
    370.             break;
    371.  
    372.             case 2:// deactivate at start
    373.             break;
    374.  
    375.             case 3: //activate at start, deactivate at end
    376.             break;
    377.  
    378.             case 4: //deactivate at end
    379.             break;
    380.         }
    381.     }
    382.  
    383.     public IEnumerator Handle2D()
    384.     {
    385.         Debug.Log("Print if you get in this function.");
    386.         print("Previous State: " + previousState + " Current State: " + currentState);
    387.  
    388.         //Not in Scene -> is cursor
    389.         if(previousState == 0 && currentState == 2)
    390.         {
    391.             Debug.Log("Print this if you get here. 1.");
    392.             controlCenter.GetComponent<GameData>().currentCursor = guiTexture.texture;
    393.             Debug.Log(guiTexture.texture);
    394.             gameObject.guiTexture.enabled = false;
    395.             cursor = controlCenter.GetComponent<GameData>().currentCursor.ToString() ;
    396.         }
    397.         else
    398.         {
    399.  
    400.             ProcessObject(currentState);
    401.         }
    402.  
    403.         //Not in scene -> In Inventory
    404.         if(previousState == 0 && currentState == 1)
    405.         {
    406.             Debug.Log("Print this if you get here. 2.");
    407.             controlCenter.SendMessage("AddToInventory", gameObject);
    408.             gameObject.guiTexture.enabled = true;
    409.             cursor = controlCenter.GetComponent<GameData>().currentCursor.ToString() ;
    410.  
    411.         }
    412.         else
    413.         {
    414.             ProcessObject(currentState);
    415.         }
    416.  
    417.         //Is Cursor -> Not in scene
    418.         if(previousState == 2 && currentState == 0)
    419.         {
    420.             Debug.Log("Print this if you get here. 3.");
    421.             controlCenter.SendMessage("ResetCursor");
    422.             gameObject.guiTexture.enabled = true;
    423.             yield return new WaitForSeconds(1.0f);
    424.             gameObject.SetActive(false); //deactivate the object immediately ... there is also supposed to be a yield above this line, I just took it out
    425.         }
    426.         else
    427.         {
    428.             ProcessObject(currentState);
    429.         }
    430.  
    431.         //Is Cursor -> In Inventory
    432.         if(previousState == 2 && currentState == 1)
    433.         {
    434.             Debug.Log("Print this if you get here. 4.");
    435.             controlCenter.SendMessage("AddToInventory", gameObject);
    436.             gameObject.guiTexture.enabled = true;
    437.             cursor = controlCenter.GetComponent<GameData>().currentCursor.ToString() ;
    438.             controlCenter.SendMessage("ResetCursor");
    439.         }
    440.         else
    441.         {
    442.             ProcessObject(currentState);
    443.         }
    444.  
    445.         //In Inventory -> Not in scene
    446.         if(previousState == 1 && currentState == 0)
    447.         {
    448.             Debug.Log("Print this if you get here. 5.");
    449.                  
    450.             controlCenter.SendMessage("RemoveFromInventory", gameObject);
    451.             yield return new WaitForSeconds(.1f);          
    452.             gameObject.guiTexture.enabled = false;                      
    453.             controlCenter.SendMessage("ResetCursor");
    454.             cursor = controlCenter.GetComponent<GameData>().currentCursor.ToString();
    455.          
    456.         }
    457.         else
    458.         {
    459.             ProcessObject(currentState);
    460.         }
    461.  
    462.         //In inventory -> Is Cursor
    463.         if(previousState == 1 && currentState == 2)
    464.         {
    465.             Debug.Log("Print this if you get here. 6.");
    466.             gameObject.guiTexture.enabled = false;
    467.             controlCenter.SendMessage("RemoveFromInventory", gameObject);
    468.             controlCenter.GetComponent<GameData>().currentCursor = guiTexture.texture;
    469.             cursor = controlCenter.GetComponent<GameData>().currentCursor.ToString() ;
    470.         }
    471.         else
    472.         {
    473.             ProcessObject(currentState);
    474.         }
    475.     }
    476. }
    I know that's a wall of text. Sorry. Hoping a fresh pair of eyes will spot whatever dumb mistake I'm making faster than me just staring at it some more.
     
  20. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    Hi fitpixel,

    "So I've done something crazy. I'm converting JS to C# on the fly while going through your book" hahaha- spoken like a true adventurer!


    The first thing I would triple check is your "replacement" object in the Inspector and make sure the string in the Lookup parameter is exactly correct- spelling, no extra spaces, etc. It is making it through to the auxiliary code, so syntax for the line must be okay.

    Debug.Log(readString + "'s new state = " + readString[i+1]);
    is that line printing out exactly what you expect? No spaces before the 's in "'s new state = "?

    If you are sure the name is correct, then the next thing to do is to check to make sure the replacement object is getting stored in the list of inventory objects (I think we generate a list at some point earlier in the chapter?). If it isn't listed, it is probably missing its inventory tag.

    If it still doesn't work, try bringing up a different inventory object instead of the current one to see if it works. That can help you decide if the problem is the processing code or the object itself (or its name in the Inspector).


    hope I've come up with something you haven't already tried

    Sue
     
  21. fitpixel

    fitpixel

    Joined:
    Apr 3, 2014
    Posts:
    2
    Okie dokie, so I thought about what you said as the replacement object getting stored in the inventory array. On second look, no, it wasn't showing up in the inventory array on the level load. However, before I didn't think this was a problem because of the CheckForActive() function. Shouldn't this function be going through the array and checking if that object is active, and if not, activating it?

    What it's doing instead, like it should, is finding the game object and assigning it to auxObject.

    You were right though, I herpderped with the name. It was missing an R. AN R. Don't judge, it's been a long week.

    Also, thanks for the speedy reply. It's great you take time out of your schedule to help people with your book!

    The CheckForActive(), just for reference in what I am talking about:
    Code (CSharp):
    1. public GameObject CheckForActive (string name)
    2.     {      
    3.         Debug.Log("Did you check for active objects?");
    4.         Debug.Log(name);
    5.         //check to see if the object is active before assigning it to the auxObject
    6.         if(GameObject.Find(name))
    7.         {
    8.  
    9.             auxObject = GameObject.Find(name);
    10.             this.gameObject.guiTexture.enabled = true;
    11.             Debug.Log(auxObject);
    12.             return auxObject;//return the gameObject to where the function was called
    13.         }
    14.  
    15.         else
    16.         {
    17.             //for the action objects
    18.             Debug.Log("Into the else statement?");
    19.             GameObject[] actionObjects = new GameObject[0];
    20.  
    21.             Debug.Log(actionObjects);
    22.             actionObjects = controlCenter.GetComponent<GameData>().actionObjects;
    23.             for (int x = 0; x < actionObjects.Length; x++)
    24.             {
    25.                 Debug.Log(actionObjects + "in the for loop");
    26.                 if(actionObjects[x].gameObject.name == name)//if there is a match for the name
    27.                 {
    28.                     Debug.Log("Into the if for the for loop?");
    29.                     actionObjects[x].gameObject.SetActive(true);
    30.                     auxObject = GameObject.Find(name); //assign the newly activated object
    31.                 }
    32.                 Debug.Log(auxObject);
    33.             }
    34.            
    35.             //for the inventory objects
    36.             Debug.Log("Into the else statement?");
    37.             GameObject[] inventoryObjects = new GameObject[0];
    38.  
    39.             Debug.Log(inventoryObjects);
    40.             inventoryObjects = controlCenter.GetComponent<GameData>().inventoryObjects;
    41.             for (int x = 0; x < inventoryObjects.Length; x++)
    42.             {
    43.                 Debug.Log(inventoryObjects + "in the for loop");
    44.                 if(inventoryObjects[x].gameObject.name == name)//if there is a match for the name
    45.                 {
    46.                     Debug.Log("Into the if for the for loop? ");
    47.                     inventoryObjects[x].gameObject.SetActive(true);
    48.                     auxObject = GameObject.Find(name); //assign the newly activated object
    49.                 }
    50.                 Debug.Log(auxObject);
    51.             }
    52.         }
    53.            
    54.         return auxObject;              
    55.                
    56.     }
     
  22. WhispersInTheRain

    WhispersInTheRain

    Joined:
    May 14, 2014
    Posts:
    4
    Alright so I found a way past this issue by combining your workaround with some of the instructions in the book. I got the key to animate upwards and the script working so it can be picked. But when I try to add the fade out to the animation in the Animation Editor and it won't let me change the Alpha value in the Editor. It just stays at 1 and if I change it to 0 it flips back to 1 regardless of what number I put in.
     
  23. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    right, that's what I found- you could get the move animating with Animation, but if you tried to add a fade and there was an Animation component, the fade won't work.
    The only way I could get the fade to work is to only use the Animator & Mecanim
     
  24. slimste

    slimste

    Joined:
    Feb 5, 2013
    Posts:
    7
    seu

    could you tell me on p 98 how to get an Splatalpha 0 object because there is nothing in the terrain asset
     
  25. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    Unity no longer exposes the splat maps to the inspector
     
  26. slimste

    slimste

    Joined:
    Feb 5, 2013
    Posts:
    7
    on p 111 is say click edit trees , add Tree and select Big tree this time , but i don't see any big Tree?
     
  27. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    you will need to import the Tree Creator package for that one
     
  28. slimste

    slimste

    Joined:
    Feb 5, 2013
    Posts:
    7
    on p 115 open custum package . navigate to the book assets folder , ch04 , assets04 , and select terrain Assets.unitypackage, i don' t see any book assets folder
     
  29. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    have you downloaded the book's assets from the Apress website?

    if so, are you sure you downloaded the assets for the 2nd edition rather than the first ? (a few people have done that by mistake)
     
  30. slimste

    slimste

    Joined:
    Feb 5, 2013
    Posts:
    7
    seu

    small problem around p 144 i have to put first person controller in the scene and once i click play it fals through the terrain
     
  31. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    Lift it up a little higher- if it intersects the ground it will fall through on start up
     
  32. WhispersInTheRain

    WhispersInTheRain

    Joined:
    May 14, 2014
    Posts:
    4
    So I've moved up to Page 338 where it's time to start activating the State Engine. I go to pick the Rock and the State changes like it should and I hear the sound effect but no animation triggers, same thing if I deactivate the Rock and try picking the KeyAtRock. Any ideas why this might be?
     
  33. slimste

    slimste

    Joined:
    Feb 5, 2013
    Posts:
    7
    i did that but then there is another problem , it falls through the bottem and goes falling some where else on the terrain
     
    Last edited: Jun 30, 2014
  34. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    @ WhispersInTheRain, Re animation- Are you mixing Animation with Animator? If you do the fade animation with Animator, but the object is still in the group with the Animator, I seem to remember the animation won't work. If that is the case, remove the rock and key from the Action Objects(?) group. If you are using Animator, be sure to use the alternative code in my earlier post

    @ slimste, Re falling- the terrain is not going to lose its collider, so that leaves 3 possibilities, 1- the fpc's capsule collider has been removed (not likely) or the Is Trigger parameter has been turned on (possible). The other possibility is that you still aren't above the ground (which can easily happen if you are starting on a hillside).
    So, change the view to a side iso and pull the fpc up higher than any terrain, switch to a top iso and make sure it is in the center of the terrain, click play and see if it stops at the ground
     
  35. MaddyJ

    MaddyJ

    Joined:
    Jul 29, 2014
    Posts:
    1
    Dear Sue,

    I'm awfully sorry to disturb you with my rather peculiar question but I can't seem to complete downloading the source files from apress. I don't have the best broadband connection & I find the download constantly interrupted & have to start from the beginning as they don't support resuming. I understand this has got to do nothing with you but I love your book but can't get started without the source files. Is there any way you could help me out regarding this matter?

    Thank you do much.

    Maddy.
     
  36. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    hi Maddy,

    PM me and I'll see if I can get you something to get you started
    the download is huge because I include the project for each chapter, but you can certainly get by with just the assets

    Sue
     
  37. koutchieman

    koutchieman

    Joined:
    May 17, 2014
    Posts:
    1
    Dear Ms. Blackman,

    I'm in chapter 10 of your book on page 354, and I'm trying to get the Pedestal to deactivate after a sound. I was able to make the Pedestal wait for the length of the sound clip before deactivating, but the sound itself would not play. The only way I could make it work was when I set the sound to Play On Awake, but I'm not sure if that is the best way to go. Do you have any idea why I would be having this problem? If so, please reply back to me.

    Thanks.
     
  38. Pilot49

    Pilot49

    Joined:
    Aug 13, 2014
    Posts:
    2
    Hello everyone,

    In chapter 8, I've noticed when I click on the rock it starts to animate, then if I click on the chest lid while the rock is in mid animation, the lid animates but the rock stops animating, it is frozen in midair but the audio clip finishes. Sort of similarly if I instead click on the chest lid first, it begins to animate, then if I click on the rock while the lid is in mid animation...the rock animates but the chest lid reverts to its closed position immediately and its sound effect continues. This interruption does NOT happen when clicking on the plant, it only seems to affect objects in the AnimationObjects group.

    Are anyone else's animations interrupted like this? Is it just me? Or is this addressed further in the book? Seems kind of important... Any thoughts? Thanks in any event :)
     
  39. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    @koutchieman
    hmmm, not sure about sound- the first thing I would check is that the object that the sound is on is not deactivated until after the sound has played (comment out the part that deactivates it)

    @Pilot49
    Yeah, that's a down side of bringing in a collection of objects with animations- the Animation component goes on the top group. If the objects are dispersed throughout the environment, it's not a problem. I think I have you duplicate the group and delete or deactivate the extra objects in each group a little farther on - that way you can have them operate independently. You could also add an Animator component and animate it through Mecanim

    Sue
     
  40. Pilot49

    Pilot49

    Joined:
    Aug 13, 2014
    Posts:
    2
    Thanks Sue for your quick reply. Now I'm having a different problem...

    Chapter 8 pages 280/281... with KeyAtRock selected (after adding its animation component) when I open the Animation Window it does not feature the KeyAtRock... none of its components are listed... so I am stuck. Anyone have a solution?
    upload_2014-8-13_20-16-50.png
    Thanks.
     
  41. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    @ Pilot49

    just tried it- you won't see the name in the Animation editor

    you should probably remove the key's Animation component

    open the Animation editor
    turn on record button
    move time indicator to 1
    move the key up in the scene view- that should generate an Animator component and you have to name the clip
    select the key's Main Color and set its alpha to 0 (black)
    move the key generated for that at frame 0 to to about frame 30
    click Play- you should see it rise and fade

    now follow the instructions in my earlier post from the second section on to keep the clip from looping, keep it from playing immediately and to trigger it from the script
     
  42. clba0003

    clba0003

    Joined:
    Aug 24, 2014
    Posts:
    1
    Hi
    I'm new in unity and have a problem in chapter 8, page 291.
    how can I replace the original animation clip of the key in the animation component?

    hope somebody can help me =)
     
  43. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    hi clba0003,

    read back several posts and you will find instructions for doing the visibility and animation with Mecanim
    Animating the Key At Rock with Mecanim
     
  44. Ijisthee

    Ijisthee

    Joined:
    Aug 30, 2014
    Posts:
    12
    Hello Sue,

    first of all thanks for writing your great book! I love it.

    Now Unity released the new 4.6 beta with the new UI System.
    On page 196 you write to create a GUI Texture via "GameObjects -> create other -> GUI Texture. This menu has disappeared in 4.6.

    Can you tell me how to handly this now?

    Thanks for your answer :)

    Ijisthee


    edit:

    found out by myself:

    The new way is: GameObjects -> UI -> RawImage
    Then you have to put the image onto the Texture Setting in the Raw Image (Script) Component.
    Then it looks similar to your descriptions.
     
    Last edited: Aug 30, 2014
  45. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    Yeah, just checked, looks like GUI Texture is gone (no great loss, but it was quick & handy)

    If you use RawImage (takes a regular Texture instead of a Sprite), you will also want to check the texture type because regular textures get MIP mapped- you could change it to Advanced & turn MIP mapping off
    or you could use the regular Image (takes a Sprite type)- not sure of the extra overhead- and change the texture type to Sprite

    either way, you will probably want to change the Scene view to 2D while you are setting that up

    I'm heading back to GUI stuff in a couple of days, so should be better able to come up with workarounds for the latest UI changes

    thanks for the heads-up!
    Sue
     
  46. Ijisthee

    Ijisthee

    Joined:
    Aug 30, 2014
    Posts:
    12
    Thanks a lot for your fast answer.

    I wass googling for the scripting part of this lession.
    guiTexture.pixelInset does seem to do not work anymore.

    I get an error from the Console:
    MissingComponentException: There is no 'GUITexture' attached to the "GamePointer" game object, but a script is trying to access it.

    As you can see at the picture, I set it up correctly, didn't I?



    And here is the code

    Code (JavaScript):
    1. #pragma strict
    2.  
    3.  
    4.  
    5. function Start () {
    6.  
    7. }
    8.  
    9. function Update () {
    10.     // gets the current cursor position as a vetor2 type variable
    11.     var pos = Input.mousePosition;
    12.    
    13.     // feed its x and y positions back into the GUI Tecture objetcs parameters
    14.     guiTexture.pixelInset.x = pos.x;
    15.     guiTexture.pixelInset.y = pos.y -32; //offset to top  
    16.  

    i think there is a new way to change the position. I looked for some help in the internet, but I didnt find something. In the ScriptReference there is "RectTransform". But don't know how to handle it.

    Maybe you have an idea?




    edit:

    btw it the same Error with UI->Image
     
    Last edited: Aug 30, 2014
  47. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    arrrrggghhhh! cursors! I haven't even tried that with the new system!

    let me poke at it a bit
     
  48. k3D-Junkie

    k3D-Junkie

    Joined:
    Jun 14, 2011
    Posts:
    236
    ok, looks suspiciously easy....

    use it just like a regular transform:
    transform.position.x = pos.x;
    transform.position.y = pos.y;

    looking into color change next... (because I'm psychic ;))
     
    Ijisthee likes this.
  49. Ijisthee

    Ijisthee

    Joined:
    Aug 30, 2014
    Posts:
    12
    Learning never stops ;)

    it works... now i just have to play with some values, because the cursor is a not on the same position. Maybe this has changed, too.

    THANKS A LOT!! My sunday is save. I can go on with learning from your great book! :=)
     
  50. Ijisthee

    Ijisthee

    Joined:
    Aug 30, 2014
    Posts:
    12
    A little change is there, too:

    Page 220 15. Set the X and Y Pixel Inset values to -16 [...]

    This doesnt work. You have to set the "Rect Transform" width and height to 16.
    And you have to change your code from

    Code (JavaScript):
    1.  
    2. guiTexture.pixelInset.x = pos.x;
    3. guiTexture.pixelInset.y = pos.y -32;
    to

    Code (JavaScript):
    1.  
    2. transform.position.x = pos.x;
    3. transform.position.y = pos.y -16;
    4. // see the -16 instead of -32 because of the Rect Transform Pane
    Then
     
    Last edited: Aug 30, 2014