Skip to content

Instantly share code, notes, and snippets.

@GameDevTeacher
Last active March 31, 2020 15:27
Show Gist options
  • Save GameDevTeacher/8f90e2e2371893b3e25f97991e1d7ac5 to your computer and use it in GitHub Desktop.
Save GameDevTeacher/8f90e2e2371893b3e25f97991e1d7ac5 to your computer and use it in GitHub Desktop.
Must be used in a project which contains Dialogue Runner and all other Yarn Spinner scripts.
/*
The MIT License (MIT)
Copyright (c) 2015 Secret Lab Pty. Ltd. and Yarn Spinner contributors.
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 UnityEngine;
using System.Collections;
using Yarn.Unity;
// This script shows how to access Yarn variables and how to affect them.
public class YarnVariableAccess : MonoBehaviour {
//Initialize Yarn variables and Yarn objects
DialogueRunner _dr;
Yarn.Unity.VariableStorageBehaviour _var;
void Awake ()
{
//Loading objects
_dr = GameObject.Find("Dialogue").GetComponent<DialogueRunner>();
_var = _dr.variableStorage;
}
// Update is called once per frame
void Update ()
{
// Get the Current value of "$VariableName" and assign it to new Variable name : Yarn_VariableName
float Yarn_numbers = _var.GetValue ("$VariableName").AsNumber;
// Set the value of "$VariableName" to 2 each frame
//_var.SetValue ("$VariableName", new Yarn.Value("2"));
if (Input.GetMouseButtonDown (1))
{
// Print the value of Yarn_VariableName
print (Yarn_numbers);
}
if (Input.GetMouseButtonDown (0))
{
// Increment the value of Yarn_VariableName by 1
_var.SetValue ("$VariableName", new Yarn.Value(Yarn_numbers+1));
}
if (Input.GetMouseButtonDown (2))
{
// Set the value of "$VariableName" to "string Number"
_var.SetValue ("$VariableName", new Yarn.Value("2"));
}
}
/**************************************************
This is to access Commands given in Yarn Dialogue.
It makes it possible to do a lot of things through
the Dialogue.
**************************************************/
[YarnCommand("move")]
public void Move(string Ship) {
// start walking towards 'destination'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment