- Home /
Why ? Shoot Monster Bounce off the walls.Help me plz.
Why ? I shoot monsters and monster hit the wall. The monster can not move.
Thank You,
Code Java
Monster Script
var columnCount:int=4;
var rowCount:int=1;
var framPerSec=2;
var speed:float= -0.01;
var x:int=1;
function Start () {
transform.localScale.x=x;
}
function Update () {
var index:int =Time.time * framPerSec;
index=index%(columnCount*rowCount);
var size = Vector2(1.0/columnCount,1.0/rowCount);
var uIndex = index % columnCount;
var vIndex = index/rowCount;
var offset=Vector2(uIndex*size.x,1.0-size.y-vIndex*size.y);
renderer.material.SetTextureScale("_MainTex",size);
renderer.material.SetTextureOffset("_MainTex",offset);
transform.position.x+=speed;
}
function OnCollisionEnter (collision:Collision)
{
if(collision.gameObject.tag =="wallban")
{
x=x*-1;
transform.localScale.x= x;
speed=speed*-1;
}
}
cats222.jpg
(38.1 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613095203im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to move a object to my position? 2 Answers
Monster AI patrol an idle 0 Answers
A simple monster spawner. 2 Answers