Unity: Difference between revisions
Jump to navigation
Jump to search
Created page with "=Introduction= ==Mouse Manager== Demonstrated who to do a mouse manager which determines what the cursor should look like when interaction with an object occurs. To do this th..." |
|||
Line 27: | Line 27: | ||
OnClickEnvironment.Invoke | OnClickEnvironment.Invoke | ||
} | } | ||
</syntaxhighlight> | |||
*The assign the NavMeshAgent destination to the OnClickEnvironment | |||
==Player Interactions== | |||
We can capture and change the destination on collision | |||
<syntaxhighlight lang="cs"> | |||
// Can store the data with a collision | |||
// Assign the new co-ordinates | |||
Transform doorway = hit.collider.gameObject.transform | |||
OnClickEnvironment.Invoke(doorway.position) | |||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 05:09, 29 August 2021
Introduction
Mouse Manager
Demonstrated who to do a mouse manager which determines what the cursor should look like when interaction with an object occurs. To do this they
- Create game object called Mouse Manager
- Set up a script which exposes 5 different Texture2d textures extending monobehaviour
- Implement update which is fired for each frame
- Import assets for cursors, set the texture type to cursor
- Attach Script to Mouse Manager object
- Drag drop assets to Mouse Manager slots from script
- Make an new layer and name it clickable
- Go to mouse manager and say clickable is possible on clickable layer
Movement
This was quite complex (maybe first time around)
- Import the NavMeshComponents
- Add NavMesh Surface empty game object
- Set the agent type on NavMesh Surface Object
- Pressing bake shows what cannot move
- We need to exclude the player from this
- To exclude the player we need to
- On the mesh exclude the player layer
- On the Player object assign the player layer to the player object
- Next create a player controller class in a script which has an agent and within start() we get this agent with GetComponent<NavMeshAgent>()
- Back in the mouseManager script create a delegate for EventVector3 OnClickEnvironment
- In the clickable if statement call the function assigned to the delegate from the GUI
if(input.GetMouseButtonDown(0)) {
OnClickEnvironment.Invoke
}
- The assign the NavMeshAgent destination to the OnClickEnvironment
Player Interactions
We can capture and change the destination on collision
// Can store the data with a collision
// Assign the new co-ordinates
Transform doorway = hit.collider.gameObject.transform
OnClickEnvironment.Invoke(doorway.position)