Created
April 2, 2018 18:39
-
-
Save dilanshah/37234a18ea8953d444443241a6bb8792 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Interviewer: Alexis Palangie Position: Apple Senior Software Engineer | |
// Date: 4/2/2018 10:30am | |
// Tested my knowledge of Unity Engine | |
// Question 1 | |
// MyBehavior b = this.GetComponent<MyBehavior>(); | |
// transform.parent.gameobject | |
// template<T> | |
// T GetComponentInParent() | |
// template<T> T GetComponent() | |
// look into the gameObject that own the behavior you're in | |
// look for a component of type t | |
// if in the hierarchy of parents if no one has component of type T it will return null | |
// rtype: | |
template<T> T GetBehavior(GameObject p){ | |
if(p.GetComponent<T>() != null){ | |
return p.GetComponent<T>(); | |
}else if (p.transform.parent != null{ | |
return GetBehavior(p.transform.parent.gameobject); | |
} | |
else | |
return null; | |
} | |
// Question 2 | |
// attach to behavior | |
// params: | |
// gameObject to point to | |
// duration (type?) | |
// function: when the game starts the gameObject that | |
// the script is attached to will move in a linear fashion in such a way that it reaches the other gameObject as the time elapse | |
// lerp | |
using UnityEngine; | |
using System.Collections; | |
public class MoveGameObject:MonoBehaviour { | |
GameObject next; | |
float duration = 0.0f; | |
void MoveInFixedTime(float fixedTime) { | |
Lerp(this.transform.position, next.transform.position, fixedTime); | |
} | |
// not sure if onAwake or Start should be used | |
private void Start() { | |
// next.transform.position | |
} | |
void Update() { | |
MoveInFixedTime(duration); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment