Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Can I do that ? How thx in advice.

Discussion in 'Scripting' started by benqowny, Feb 12, 2020.

Thread Status:
Not open for further replies.
  1. benqowny

    benqowny

    Joined:
    Apr 1, 2018
    Posts:
    11
    public void assignAIToTarget<T>(T target)
    {

    if (typeof(Vector3) == target.GetType())
    {
    _targetingTransform = false;
    _targetPosition = target.position;
    repeatFollowOrder();
    }
    else if (typeof(Transform) == target.GetType())
    {
    _targetTransform = target;
    _targetingTransform = true;
    repeatFollowOrder();
    }
    }
     
  2. benqowny

    benqowny

    Joined:
    Apr 1, 2018
    Posts:
    11
    ZenvinDziś o 22:11
    how about
    public void AssignAIToTarget<T> (T target) where T : Transform where T : Vector3 {
    if (target is Vector3 v) {
    targetingTransform = false;
    targetPosition = v;
    } else if (target is Transform t) {
    targetingTransform = true;
    targetTransform = t;
    } else {
    return;
    }
    RepeatFollowOrder ();
    }
     
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,742
    1) Use code tags.
    2) Do what? Without knowing what you're trying to do with this, we can't tell you anything more than whether or not the code compiles.
     
    Yoreki likes this.
  4. benqowny

    benqowny

    Joined:
    Apr 1, 2018
    Posts:
    11
    Code (CSharp):
    1.  
    2. public void assignAIToTarget<T>(T target)
    3. {
    4.  
    5. if (typeof(Vector3) == target.GetType())
    6. {
    7. _targetingTransform = false;
    8. _targetPosition = target.position;
    9. repeatFollowOrder();
    10. }
    11. else if (typeof(Transform) == target.GetType())
    12. {
    13. _targetTransform = target;
    14. _targetingTransform = true;
    15. repeatFollowOrder();
    16. }
    17. }
    so many buttons ...
     
  5. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,742
    You still haven't said what you're trying to do.
     
    Joe-Censored likes this.
  6. benqowny

    benqowny

    Joined:
    Apr 1, 2018
    Posts:
    11
  7. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,742
    USE. WORDS. Tell us what you are trying to do.
     
    zombiegorilla and Joe-Censored like this.
  8. benqowny

    benqowny

    Joined:
    Apr 1, 2018
    Posts:
    11
  9. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,742
    For the love of....

    Do not post another screenshot. Do not post another block of code. SAY SOMETHING

    Tell us, in words, what you are trying to accomplish.
     
  10. benqowny

    benqowny

    Joined:
    Apr 1, 2018
    Posts:
    11
    Well... With last screenshot I show the solution. So what is this talking is for ?
     
  11. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,742
    https://media1.giphy.com/media/X83Y7r03T6uty/giphy.gif
    Literally so that the people trying to help you can know that you no longer need help. We cannot read your mind.
     
    Joe-Censored and Madgvox like this.
  12. benqowny

    benqowny

    Joined:
    Apr 1, 2018
    Posts:
    11
    How do you know that sir ?
     
  13. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,742
    .....what
     
  14. benqowny

    benqowny

    Joined:
    Apr 1, 2018
    Posts:
    11
    That's kinda out of topic. So maybe you want to message me, sir :)
     
  15. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Check out method overloading. There's no need to use generics in this particular case.
     
  16. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,972
    Closing for incoherent nonsense.
    1) use code tags.
    2) post a clear question.
    3) write coherently.
     
    Ryiah and Joe-Censored like this.
Thread Status:
Not open for further replies.