I want to create something like a third person adventure.
My problem is that I’m a really terrible programmer.
I want to build a mouseover effect and if i click i want my charackter to say something.
I thougt i can build this with raycast but i dont understand how to use it. does it work in connection with the camera?
hope you can help me!
It’s easy. Make sure you have a collider connected to your character, then include a script like this:
// Fades the red component of the material to zero
// while the mouse is over the mesh
function OnMouseOver () {
renderer.material.color.r -= 0.1 * Time.deltaTime;
}
More info here:
To start the NPC talking, you’ll want to use OnMouseDown (that’s when you actually click). I like the on Mouse Over to make things glow so the player knows they can interact with the object. Dont forget to use OnMouseExit to make it stop glowing when the mouse isn’t over it any more!
Thanks!!! This will come in handy for me in the future!!!
Thanks a lot, thats really great.
But how would you let something glow?
I love this stuff.
private var highlightMultiply = 2.5;
private var originalColor;
function Start () {
// get original color for Glow functions
originalColor = renderer.material.color;
}
function OnMouseEnter(){
Glow();
}
function OnMouseExit(){
NoGlow();
}
function Glow() {
renderer.material.color.r = originalColor.r*highlightMultiply;
renderer.material.color.g = originalColor.g*highlightMultiply;
renderer.material.color.b = originalColor.b*highlightMultiply;
}
function NoGlow() {
renderer.material.color = originalColor;
}
THe glow effect isn’t working…
this is JScript right?
The thing about this script is that it needs to be attached to a collider to work, and will make that collider glow. If you want a different component or a child object to glow, then you’ll have to reference that object to glow. If it’s a child you will have to modify the script like this:
private var highlightMultiply = 2.5;
private var originalColor;
private var glowingObject;
function Start () {
glowingObject = transform.Find("ObjectName");
// get original color for Glow functions
originalColor = glowingObject.renderer.material.color;
}
function OnMouseEnter(){
Glow();
}
function OnMouseExit(){
NoGlow();
}
function Glow() {
glowingObject.renderer.material.color.r = originalColor.r*highlightMultiply;
glowingObject.renderer.material.color.g = originalColor.g*highlightMultiply;
glowingObject.renderer.material.color.b = originalColor.b*highlightMultiply;
}
function NoGlow() {
glowingObject.renderer.material.color = originalColor;
}
That’s what comes to mind. Are you getting any errors?
no errors, but i don’t understand how to attach the script to a collider, i can attach it to an object, but not directly to the collider
Right. A collider is a component of an object. Attach the script to the object and make sure there is a collider component. Whatever is glowing is a mesh, right? so it might be easiest to select that mesh and go to add component → physics → mesh collider. Check “is trigger”
ha i got it working right after i posted it wasn’t working
Thanks a lot!!! love this script, will be perfect for my game!
Yeah thats damn cool thanks a lot.
Next problem will be a bit more complicating.
i need my character to sit in a box (car) and follow a spline. I saw some of the path tools, but wich should i use.
And the second is, i want adventure like conversation, when i click a character that i get a menu where i can choose what to say. is there any tutorial how to write something like this?
BTW. here are my first Results:
www.Maksimilian.de/neu.Html
I want to Programm everything first. Later i’ll add my graphics.