Tuesday, December 26, 2017
Unity: checking errors
If you cannot build to a mobile device for some reason, it may be due to a compiler error. To check, open the console window, click the bottom on the top right corner and 'open editor log'. This will contain detailed information as to why the project could not build.
Friday, December 22, 2017
Unity: Access child of a gameobject
GameObject ChildGameObject = ParentGameObject.transform.GetChild(i).gameObject;
where i is the index of the child transform.
Wednesday, December 13, 2017
PhD comics
A list of personally relatable PhD comics when I was completing my thesis.
References
Life Plan vs. Life Reality
Data: by the numbers
Conference
Writing your Thesis Outline
Your Thesis Title
The Actual Method
Seminar Bingo
More of the same
Keeping your paper within the page limit
Quantum Gradnamics, pt. 1 of 3
Quantum Gradnamics, pt. 2 of 3
Quantum Gradnamics, pt. 3 of 3
Research Diagram/Research Reality
Your Life Ambition
Vicious Cycle
How to ruin a grad student's evening
Average time spent writing one e-mail
How long your Prof. thinks it should take to do something
Clever Acronyms
Abstract Mad Libs
Vacation v. Stress
Buzzwords
A story in file names
Call for Papers!
Too due list
The Repulsor Field Explained
Procrascorrelation
The Out-Of-Office Reply
Intellectual Freedom
The Methodology Translator
The Plans
Your Thesis Outline
References
Life Plan vs. Life Reality
Data: by the numbers
Conference
Writing your Thesis Outline
Your Thesis Title
The Actual Method
Seminar Bingo
More of the same
Keeping your paper within the page limit
Quantum Gradnamics, pt. 1 of 3
Quantum Gradnamics, pt. 2 of 3
Quantum Gradnamics, pt. 3 of 3
Research Diagram/Research Reality
Your Life Ambition
Vicious Cycle
How to ruin a grad student's evening
Average time spent writing one e-mail
How long your Prof. thinks it should take to do something
Clever Acronyms
Abstract Mad Libs
Vacation v. Stress
Buzzwords
A story in file names
Call for Papers!
Too due list
The Repulsor Field Explained
Procrascorrelation
The Out-Of-Office Reply
Intellectual Freedom
The Methodology Translator
The Plans
Your Thesis Outline
Thursday, November 9, 2017
Tuesday, October 31, 2017
Different ways of enabling mouse click as event trigger in Unity via scripting
For a 2D object/sprite:
Option 1:
Option 1:
1. In the script file, include using UnityEngine.EventSystems; at the top.
2. Implement the PointerClick interface
3. Attach the script to the 2D sprite and make sure that a 2D collider (e..g box collider 2D) is attached to it.
4. Select the camera and attach Physics 2D raycaster to it.
using System.Collections;
using UnityEngine;
using UnityEngine.EventSystems;
public class clickTester : MonoBehaviour, IPointerClickHandler
{
public void OnPointerClick (PointerEventData eventData)
{
//do something here, e.g. change colour of sprite.
GetComponent<SpriteRenderer>().color = new Color(1f,0.3f, 0.30196078f);
print ("Pointer click");
}
}
Source: https://stackoverflow.com/questions/37452457/unity-3d-enabling-mouse-pointer-as-a-event-triggers-pointer-enter-exit/37456107#37456107
Option 2:
1. Ensure the 2D sprites have a 2D collider attached to them.
2. Attach a script file to the camera with the code below.
For a UI button:
1. In the script file, include using UnityEngine.UI; at the top.
2. Make a public void method and give it a name
3. In the button, add an Event Trigger component -> Add New Event Type -> Pointer Click.
4. Drag the gameobject the script is attached to into the pointer click.
5. Choose the public void method created.
Option 2:
1. Ensure the 2D sprites have a 2D collider attached to them.
2. Attach a script file to the camera with the code below.
using System.Collections;
using UnityEngine;
public class clickTester: MonoBehaviour {
void Update()
{
if (Input.GetMouseButtonDown(0)) //This is left mouse button click
{
//Converting Mouse Pos to 2D (vector2) World Pos
Vector2 rayPos = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
RaycastHit2D hit = Physics2D.Raycast(rayPos, Vector2.zero, 0f);
if (hit)
{
//do something here, e.g. change colour of sprite.
GetComponent<SpriteRenderer>().color = new Color(1f,0.3f, 0.30196078f);
print ("Pointer click");
}
}
}
}
For a UI button:
1. In the script file, include using UnityEngine.UI; at the top.
2. Make a public void method and give it a name
3. In the button, add an Event Trigger component -> Add New Event Type -> Pointer Click.
4. Drag the gameobject the script is attached to into the pointer click.
5. Choose the public void method created.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class button : MonoBehaviour
{
public void changeColour(){
//Do something here, e.g. change colour of button.
GetComponent<Image>().color = Color.green;
print ("testing changeColour");
}
}
Monday, October 16, 2017
Using Git
- Install Git from https://git-scm.com/download/win
- Navigate to the folder where you want to create the repository and type:
git init
- Set your name and address:
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
- Set your text editor. E.g. If your editor is sublime text, type:
git config --global core.editor "'C:/Program Files/Sublime Text/sublime_text.exe' -multiInst -nosession"
Common commands:
git status
Shows what files have changed since the last commit.
git log
Shows commit log
git add .
Adds all modified files to staging area
git commit
Commit/records changes to the repository. This will open up an associated editor (e.g. notepad, sublime text, etc).
git checkout -b [name_of_new_branch]
Create a new branch
git branch -d [name_of_branch]
Delete a branch
git ls-tree -r master --name-only
Shows a list of all files currently being tracked under the branch master.
git ls-tree -r HEAD --name-only
Shows a list of all files currently being tracked under the current branch.
git add .
git stash
git checkout master
This is to switch back to the head if you have checked out an earlier commit.
Other:
To ignore directories, i.e. directories you don't want to commit, edit the .git/info/exclude file and add the directory you want to ignore, e.g. if the folder you want to ignore is called Temp, add
Temp/ to the exclude file.
- Navigate to the folder where you want to create the repository and type:
git init
- Set your name and address:
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
- Set your text editor. E.g. If your editor is sublime text, type:
git config --global core.editor "'C:/Program Files/Sublime Text/sublime_text.exe' -multiInst -nosession"
Common commands:
git status
Shows what files have changed since the last commit.
git log
Shows commit log
git add .
Adds all modified files to staging area
git commit
Commit/records changes to the repository. This will open up an associated editor (e.g. notepad, sublime text, etc).
git checkout -b [name_of_new_branch]
Create a new branch
git branch -d [name_of_branch]
Delete a branch
git ls-tree -r master --name-only
Shows a list of all files currently being tracked under the branch master.
git ls-tree -r HEAD --name-only
Shows a list of all files currently being tracked under the current branch.
git add .
git stash
git checkout master
This is to switch back to the head if you have checked out an earlier commit.
Other:
To ignore directories, i.e. directories you don't want to commit, edit the .git/info/exclude file and add the directory you want to ignore, e.g. if the folder you want to ignore is called Temp, add
Temp/ to the exclude file.
Sunday, October 15, 2017
Different ways of disabling game object/component in Unity via scripting
Example: HingeJoint2D. When the spacebar is pressed, the object/component is disabled.
1. To disable the entire game object, you can use Destroy. Make sure to tag the appropriate game object.
2. To deactivate the game object, use SetActive(false)
3. Use GetComponent to disable only the HingeJoint2D component, and not the entire game object.
1. To disable the entire game object, you can use Destroy. Make sure to tag the appropriate game object.
private GameObject joint;
void Start(){
joint = GameObject.FindWithTag("joint");
}
void Update() {
if (Input.GetKeyDown ("space")) {
Destroy(joint);
}
}
2. To deactivate the game object, use SetActive(false)
private GameObject joint;
void Start(){
joint = GameObject.FindWithTag("joint");
}
void Update() {
if (Input.GetKeyDown ("space")) {
joint.SetActive(false);
}
}
3. Use GetComponent to disable only the HingeJoint2D component, and not the entire game object.
private HingeJoint2D hinge;
void Start(){
hinge = gameObject.GetComponent(typeof(HingeJoint2D)) as HingeJoint2D;
}
void Update() {
if (Input.GetKeyDown ("space")) {
hinge.enabled=false;
}
}
Wednesday, September 27, 2017
Error: Windows is unable to complete disk drive format
While attempting to format a micro sd card, the error 'Windows is unable to complete disk drive format' occurred.
Solution: Use SD Memory Card Formatter (https://www.sdcard.org/downloads/formatter_4/index.html)
Solution: Use SD Memory Card Formatter (https://www.sdcard.org/downloads/formatter_4/index.html)
Sunday, August 27, 2017
Saturday, March 4, 2017
Copying and pasting data from Excel to Mathematica
Type into Mathematica ImportString["", "TSV"]
Paste the excel data between the empty double brackets.
Source: http://mathematica.stackexchange.com/questions/8997/cut-and-paste-data-from-a-spreadsheet
Paste the excel data between the empty double brackets.
Source: http://mathematica.stackexchange.com/questions/8997/cut-and-paste-data-from-a-spreadsheet
Monday, February 6, 2017
Subscribe to:
Posts (Atom)