Search Unity

What's the Coroutine Script should be in the second example ,Tutorials/Scripting/Coroutines video ?

Discussion in 'Scripting' started by Ice_MJ, Jul 26, 2016.

  1. Ice_MJ

    Ice_MJ

    Joined:
    Jul 26, 2016
    Posts:
    13
  2. zoran404

    zoran404

    Joined:
    Jan 11, 2015
    Posts:
    519
    The code posted there seems legit to me.
    What do you think is missing?
     
  3. Ice_MJ

    Ice_MJ

    Joined:
    Jul 26, 2016
    Posts:
    13

    Ok, thanks for your replay.
    The picture is a Screen Shot in this video about the second example PropertiesAndCoroutines, The prop_floorBot ... Script bind on this object is not shown below the video,that makes me confused, And I can't run this example in Unity without this script. Can you ?
     
  4. zoran404

    zoran404

    Joined:
    Jan 11, 2015
    Posts:
    519
    Well the screenshot you tried to post does not show and taking a quick look at the video I didn't see any differences to the scripts below.
    This prop_floorBot you mention seems to be material for the bot, which is completely irrelevant for a code example and you should definitely be able to run the script whichever material your models have.

    If you can't run the example in the editor please explain what errors are you getting.
     
  5. Ice_MJ

    Ice_MJ

    Joined:
    Jul 26, 2016
    Posts:
    13
    OK, I upload the picture in my google drive, you can see it here, https://drive.google.com/open?id=0B7IoPoK3hNeocW9HVjBxX0VuVnc, And I don't think this prop_floorBot is material for the bot, it is obviously that this prop_floorBot is a C# script, otherwise,how a material can be set to this Coroutine Script field?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ClickSetPosition:MonoBehaviour
    5. {
    6.     public PropertiesAndCoroutines coroutineScript;
    7.  
    8.     void OnMouseDown()
    9.     {
    10.         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    11.         RaycastHit hit;
    12.  
    13.         Physics.Raycast(ray, out hit);
    14.  
    15.         if(hit.collider.gameObject == gameObject)
    16.         {
    17.             Vector3 newTarget = hit.point + new Vector3(0, 0.5f, 0);
    18.             coroutineScript.Target = newTarget;
    19.         }
    20.     }
    21. }
     
    Last edited: Jul 26, 2016
  6. LTK

    LTK

    Joined:
    Jul 16, 2015
    Posts:
    22
    I think prop_floorBot... is gameobject prop_floorBot_female and it added component(script) PropertiesAndCoroutines.
    You can see in component ClickSetPosition have a variable with type PropertiesAndCoroutines and ClickSetPosition will reset target of PropertiesAndCoroutines
    Ok, add ClickSetPosition into Target gameobject, add PropertiesAndCoroutines into prop_floorBot_female gameobject then drop and dag prop_floorBot_female gameobject into Coroutine Script of Target gameobject
     
    Ice_MJ likes this.
  7. zoran404

    zoran404

    Joined:
    Jan 11, 2015
    Posts:
    519
    Sorry, I confused it with something else I saw in the video.

    The prop_floorBot is the name of a GameObject to which a PropertiesAndCoroutines is attached.
    You can't see the full text because the sidebar is not wide enough, but the full text is:
    Coroutine Script: prop_floorBot_female (PropertiesAndCoroutines)

    You can see the "prop_floorBot_female" GameObject in the hierarchy on the left side.

    Also if you look at folder that he opened (at the bottom) you'll see that there are only 3 scripts and those are the ones posted below the video.
     
    Ice_MJ likes this.
  8. Ice_MJ

    Ice_MJ

    Joined:
    Jul 26, 2016
    Posts:
    13
    OK, I realize I should bind the ClickSetPosition script to the Plane GameObject in my Scene, not to a new empty GameObject, cause the hit.collider.gameObject == gameObject means when you hit the Object which is the script ClickSetPosition.cs bind to, then you move the Robot which bind the PropertiesAndCoroutines.cs ,and before that you should initialize the coroutineScript with the Robot GameObject.
    Silly me...
     
  9. Ice_MJ

    Ice_MJ

    Joined:
    Jul 26, 2016
    Posts:
    13
    Thanks a lot, I totally understand that, haha :>
     
  10. Ice_MJ

    Ice_MJ

    Joined:
    Jul 26, 2016
    Posts:
    13
    Yep, I got it, I should add ClickSetPosition into Target gameobject, add PropertiesAndCoroutines into prop_floorBot_female gameobject then drop and dag prop_floorBot_female gameobject into Coroutine Script of Target gameobject just like LTK pointed.
    Thanks a lot man!