Last active
July 2, 2018 04:09
-
-
Save rocky1138/0007bb1c78c73c2d34dbd17ed63b1810 to your computer and use it in GitHub Desktop.
Snap Dialogue UI to NPC Game Object (Dialogue System for Unity)
This file contains hidden or 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
/* | |
MIT License | |
Copyright (c) 2018 John Rockefeller | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. | |
*/ | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class SnapDialogueUIToNPC : MonoBehaviour { | |
public Canvas canvas; | |
public Vector3 offset = new Vector3(0.0f, -0.65f, 1.1f); | |
private void OnConversationStart (Transform actor) { | |
var camTransform = Camera.main.transform; | |
canvas.transform.position = camTransform.position + camTransform.forward * offset.z + camTransform.right * offset.x + Vector3.up * offset.y; | |
canvas.transform.rotation = Quaternion.Euler(canvas.transform.rotation.eulerAngles.x, camTransform.rotation.eulerAngles.y, canvas.transform.rotation.eulerAngles.x); | |
canvas.transform.SetParent (gameObject.transform); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment