Wednesday, April 19, 2017

Day 36: Audio-only Game: Day 11

I needed a way for the raycast to interact with objects. First I made a RayCastHit variable called "WhatIHit".

Next, I added some script in the "if" statement that stores the data for the item the raycast hit in the variable.

Next, I changed the Debug.Log so it would output "I hit" and then the the name of the object it hit, which I accessed through the collider of the object.


As you can see, the console is outputting "I hit terraaced1am", which is the name of the house model that the raycast is touching.

Now to have the raycast subtract health from a character. I made a new capsule object called "enemy" just to test it, and gave it a RigidBody.

I then added the Health script on to it. The script only contains the health variable, and nothing else for now.


Unfortunately I don't yet know how I would have the raycast change the variable on hit. So far, I have enough script for it to access a component, but I don't know how to specify which component, or how to change a variable in the component.

I posted a question on the Unity3D forum, so hopefully I'll have an answer in a couple days or so.

Until then, I'll add more to the Health script.















No comments:

Post a Comment